fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.nio.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. StringBuffer texto = new StringBuffer("Data Valor\n20140901 278\n20140902 248\n20140903 458\n20141004 545\n20141005 125\n20141106 1020\n20141207 249");
  14.  
  15. CharBuffer buffer = CharBuffer.wrap(texto);
  16. int inicio = 0, fim = 0;
  17. while ( fim < buffer.capacity() ) {
  18. if ( buffer.get(fim) == '\n' ) {
  19. buffer.position(inicio).limit(fim);
  20. // Usa-se buffer como se fosse uma String
  21. System.out.println(buffer);
  22. buffer.position(0).limit(buffer.capacity());
  23. inicio = fim+1;
  24. }
  25. fim++;
  26. }
  27. }
  28. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
Data            Valor
20140901        278
20140902        248
20140903        458
20141004        545
20141005        125
20141106        1020