This discussion is archived
2 Replies Latest reply: Feb 12, 2008 3:07 PM by 807603 RSS

procesing data from a text file

807603 Newbie
Currently Being Moderated
Hi

If somebody can give my some hints how to write java program that will sort a marks from a file "Java.txt". The program should print to the screen the records of students with the top two marks, middle two marks, and bottom two marks.
For example it is my "Java.txt"
0123333,23
0234447,34
0278787,2
and so on to 100 numbers when after comma is mark

This is my program but how can I modified that to sort my marks 23 34 2 and so on

import java.io.*;
class TestFileReader {
public static void main(String args[]) {
try {
FileReader fin=new FileReader("TextProbe.txt");
System.out.println("Canonic name of text coding: "+
          fin.getEncoding());
int c;
while(fin.ready()) {
c=fin.read();
System.out.print((char)c);
}
System.out.println();
fin.close();
fin=new FileReader("TextProbe.txt");
char[] tab=new char[80];
int nrChar;
nrChar=fin.read(tab);
System.out.println("Numner of read characters: "+nrChar);
for (int i=0; i<nrChar; i++) System.out.print(tab);
System.out.println();
fin.close();
tab=new char[12];
fin=new FileReader("TextProbe.txt");
while(fin.ready()) {
nrChar=fin.read(tab);
for(int i=0; i<nrChar; i++) System.out.print(tab[i]);
}
System.out.println();
fin.close();
}
catch(Exception e) {
System.out.println(e);
}
}
}
probably I should use Integer.parseInt() but I have no idea how to use that
I will be very apreciate for help