Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2010
    Posts
    4
    Rep Power
    0

    Cool 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();

    }




    }

    }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Storing data to file :s
    By idi in forum New To Java
    Replies: 3
    Last Post: 02-13-2010, 08:54 PM
  2. Reading data to file
    By puk284 in forum Advanced Java
    Replies: 1
    Last Post: 04-28-2009, 03:19 PM
  3. getting data from a file
    By sugard in forum Advanced Java
    Replies: 2
    Last Post: 03-03-2009, 07:24 AM
  4. Storing the data in a file
    By vasavi.singh in forum New To Java
    Replies: 4
    Last Post: 02-20-2009, 04:01 PM
  5. Data Sorting in a .data file using java
    By stutiger99 in forum New To Java
    Replies: 2
    Last Post: 10-08-2008, 02:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •