JOptionpane Data to a new file
Ok, I'm created a rental car service program that allows the user to input their information and receive the results in a joptionpane dialog box. Now, I have to create a text file that will show the information exactly how the user has entered it and the same exact way that it shows up in the joptionpane dialog box. I've created the text file called lauren and the file that I'm trying to read my data from is called RentalCar. The specific string that houses all the rental car data is called Ultimate. Here is what I have so far. Thanks for helping me in advance!!:)
Code:
import java.util.*;
import java.io.*;
public class RentalCarReadFromFileWithScanner{
public static void main(String[]args){
File Lauren = new File("C:\\Lauren.txt");
try{
Scanner scn = new Scanner(Lauren);
while(scn.hasNext()){String line = scn.nextLine();
System.out.println(line);
}
}
catch(FileNotFoundException fnfe){
System.out.println("File Doesn't Exist!!!");
}
Formatter output = new Formatter();
try{
output= new Formatter("C:\\Lauren.txt");
output.format("Lauren");
output.format("\nJohn Doe");
output.close();
}
catch(FileNotFoundException fnfe){
output.close();
System.out.println("File Doesn't Exist !!!");
}
finally {
output.close();
}
}
}