
February 22nd, 2013, 06:26 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 13
Time spent in forums: 3 h 21 m 37 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by NormR The Scanner class has some methods that make it easy to read the contents of a text file. |
Code:
package edu.nyt3619.file;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class StudentGrade {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
// Open the file that is the first
// command line parameter
// checks where the path is going ??
System.out.println(System.getProperty("user.dir"));
FileInputStream fstream = new FileInputStream("StudentGrades.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
// Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println(strLine);
}
// Close the input stream
in.close();
} catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
I can get my program to read exactly what's inside the text file. I want it to display the output differently and not just read what is already inside the text file and display it out. I'm not sure how to do that? example is 1234, john, doe, 100. i want it to output student grade=100 | last name= john | first name= doe | student id=1234.
so basically swapping 1234 and 100 around while adding extra wording to let people know what is 100, john, doe, and 1234.
do i need some loop to get it to read the line after the 3rd comma, then make it read 2nd word after the first comma, then the line after 2nd comma comma and then line before first comma??
|