BufferedReader infile = new BufferedReader( new FileReader(args[0]) );
while ( infile.ready() )
{
String line = infile.readLine();
}
infile.close();
hoffmant 3.141 1991 true janedoe 4.00 2010 falseand you want to read these values from the file into variables in your program, you can do it as below if you are sure the values are formatted correctly.
Scanner infile = new Scanner (new File( args[0] ));
while (infile.hasNext() ) // while there is something left in the file to read (we ASSUME the file is formatted correctly)
{
String name = infile.next(); // grabs the next token treats as String
double gpa = infile.nextDouble();
double yrGrad = infile.nextInt();
boolean faculty = infile.nextBoolean();
}
infile.close();
PrintWriter outfile = new PrintWriter( new File(args[0]) );
int x = 235;
outfile.println("Hello World");
outfile.println("The value of x is: " + x );
outfile.close();
hoffmant 3.141 1991 true janedoe 4.00 2010 falseand you want to read these values from the file into variables in your program.
Scanner infile = new Scanner (new File( args[0] ));
while (infile.hasNext() ) // while there is something left in the file to read (we ASSUME the file is formatted correctly)
{
String name = infile.next(); // grabs the next token and leaves it as a String
double gpa = infile.nextDouble(); // grabs the next token and converts to double
int yrGrad = infile.nextInt(); // grabs the next token and converts to int
boolean faculty = infile.nextBoolean(); // grabs the next token and converts to boolean
}
infile.close();