java - How can I change this main method to read files sequentially -


how can read files sequentially ?

public static void main(string[] args){     string fichier ="e:\\fichiers\\test.txt";      int tab[] = {2, 2, 20, 8, 20, 8, 4, 3, 7, 3, 3, 3, 18, 139};     string tabs[] = new string[14];       for(int i=0; i<tab.length; i++){          char cbuf[] = new char[tab[i]];          try {              inputstream       ips  = new fileinputstream(fichier);              inputstreamreader ipsr = new inputstreamreader(ips);             bufferedreader    br   = new bufferedreader(ipsr);              br.read(cbuf, 0, tab[i]);              tabs[i] = new string(cbuf);             system.out.println(tabs[i]);          } catch (exception e){             system.out.println(e.tostring());         }     } } 

my file contents line :

bouuuuuuuuuuuuuuuuuuuuuu! 

when run readme method, got this:

bo bo bouuuuuuuuuuuuuuuuuu bouuuuuu bouuuuuuuuuuuuuuuuuu bouuuuuu bouu bou bouuuuu bou bou bou bouuuuuuuuuuuuuuuu bouuuuuuuuuuuuuuuuuuuuuu! 

the problem here every time begins read file begins position 0.

any please ?

it looks me need move loop inside try/catch after streams created.

public static void main(string[] args){     string fichier ="e:\\fichiers\\test.txt";      int tab[] = {2, 2, 20, 8, 20, 8, 4, 3, 7, 3, 3, 3, 18, 139};     string tabs[] = new string[14];      try {          inputstream       ips  = new fileinputstream(fichier);          inputstreamreader ipsr = new inputstreamreader(ips);         bufferedreader    br   = new bufferedreader(ipsr);          for(int i=0; i<tab.length; i++){              char cbuf[] = new char[tab[i]];              br.read(cbuf, 0, tab[i]);              tabs[i] = new string(cbuf);             system.out.println(tabs[i]);         }      } catch (exception e){         system.out.println(e.tostring());     } } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -