-
sorting problem...
Im trying to load data from a text file ghax display it in a text area and load the contents of the file in alphabetical order; the following piece of code which i cant get working; any one can help pls!
------------------------------------------
private void test() {
{
try {
in = new BufferedReader(
new FileReader(
new File(
"C:\\test.txt")));
// Declare Array which will hold 10 lines
String[] myarray;
int n = 10;
String lineContent = null;
myarray = new String[n];
// Read each line into the array
for (int i = 0; i < myarray.length; i++) {
myarray[i] = in.readLine();
int currentLine = 0;
// this will be set to true if the string was found
while (true) {
currentLine++;
// get a line of text from the file
try {
lineContent = in.readLine();
} catch (IOException e) {
break;
}
String str = null;// = lineContent;
StringTokenizer st = new StringTokenizer(str);
if (st.countTokens() > 1) {
System.out.println("Number of Words: " +
st.countTokens() );
Arrays.sort(myarray);
System.out.println("Sorted Strings: " + "\n"+ Arrays.asList(myarray)+"\n");}
}
}
}
catch (IOException e) {
lineLabel.setText("Error Opening Text File");
JOptionPane.showMessageDialog(null,
"The File cannot be opened.", "Information",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
--------------------the end -------------
-
-
And what is you problem?
regards,
sukatoa
-
-
Which part is not working?
regards,
sukatoa