java - distinguishing string based on space between them -


i have text file generated application contains strings this:

26     50 597 424 561 499 849 283 76 115 81 4 26  public void listingcoord() throws ioexception{      file f = new file("coord.txt");     filewriter writer = new filewriter(f);      for(string s: interationlist){      writer.write(s+"\n");     }     writer.close();      }  public void replay(){      bufferedreader br = null;     try{         string line;         br = new bufferedreader(new filereader("coord.txt"));         while((line = br.readline())!=null){             system.out.println(line);         }     }         catch (ioexception io){ io.printstacktrace();}     try {         br.close();     } catch (ioexception e) {         // todo auto-generated catch block         e.printstacktrace();     }  } 

the code listing string above. there list contains strings displayed, , list , replay methods write , read lines.

what want reading integers, in different way. know how read text file , display it, want make decision numbers so:

  • if in 1 position without spaces 26 send right method argument - have ready methods-.

  • if in 2 positions 1 space 499 849 send right method.

and on,

is there way this? mean distinguishing between number partitions based on space have between.

if understand well, have know how many numbers in line.
should read text file line-by-line, , parse integers:

import java.util.scanner; import java.io.*; public class parser{     public static void main(string[] args){ //excepiton catching needed         scanner sc = new scanner(new file(args[0])); //for example         while(sc.hasnextline()){             string line = sc.nextline();             string[] array = line.split(" ");             switch(array.length){                 case 1: oneparammethod(array[0]); break;                 case 2: twoparammethod(array[0],array[1]); break;                 default: system.out.println("strange line");             }         }         sc.close();     }     public static void oneparammethod(string param){         int value = integer.parseint(param);         // there code     }     public static void twoparammethod(string param1,string param2){         int value1 = integer.parseint(param1);         int value2 = integer.parseint(param2);         // there code     } } 

not tested
there should used array instead of switch if possible @pshemo noticed @ comment


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -