1 Attachment(s)
Setting txt file columns delimiter
Hi all,
I have a method to read a txt file with comma separated columns
Code:
public void importToArray(){
int rows = 0;
bin = new String[numberOfLines()][6];
try {
FileReader fr = new FileReader(fileToImport);
BufferedReader br = new BufferedReader(fr);
String line = null;
while((line = br.readLine())!= null){
StringTokenizer stk = new StringTokenizer(line, ",");
while(stk.hasMoreTokens()){
for (int cls = 0;cls<6; cls++){
bin[rows][cls]= stk.nextToken();
}
rows++;
}//end inner while loop
}//end outer while loop
br.close();
}//end try
catch(Exception e){
System.out.println(e);
}
}
I main class I have set a GUI where to choose different columns separators, as the attached picture.
Radio buttons are grouped in a group button so that only one button can be selected.
How should I modify my method so I can have the selected delimiter from the GUI?
Thanks.
Susanna