I have a program that suppose to display the content of this file:
http://rapidshare.co...StudentData.txt
I was able to display the student number and the last name but now I'm not able to display the test of the text's content properly.
If you'll run it, you'll see what I mean.
So can you tell me what an I doing wrong? I know it has to do something with the substring of "firstname" but don't know what.
Here's my code:
import java.io.*;
public class DisplayFile
{
public static void main(String[] args) throws IOException
{
// Open the file.
FileReader freader = new FileReader("StudentData.txt");
BufferedReader inputFile = new BufferedReader(freader);
// Read the first line from the file.
String str = inputFile.readLine();
while (str != null) // display & read lines
{
// get student number
String stno = str.substring(0,7);
// get last name
str = str.substring(8);
int i = str.indexOf(',');
String lastname = str.substring(0, i);
//get first name
str = str.substring(7);
int j = str.indexOf(',');
String firstname = str.substring(0, '\t');
// display information
System.out.println("\t"+stno+"\t\t"+lastname+"\t\t"+firstname);
str = inputFile.readLine();
}
// Close the file.
inputFile.close();
}
public static int larger(int mark1, int mark2)
{
return 0;
}}
This post has been edited by xahtep9563: 04 November 2010 - 03:35 PM

New Topic/Question
Reply



MultiQuote





|