Results 1 to 5 of 5

Thread: Console app that reads/writes data files

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    19

    Post Console app that reads/writes data files

    Another basic question, but i'd like to keep this program as simple as possible.

    I have numerous txt files that I want to read, just using the text console, not using any graphical interface options of Java.

    easiest way to go about this?

    i.e. i've got a txt file with a bunch of names/phone #'s that I want to open..

    so basically I want the finished product to look like.

    Enter file name: xxx.txt


    John Doe 123-4567
    John Smith 123-4567

    Enter output file name: xxx.txt
    Done saving file xxx.txt
    Last edited by Squirrel RJ; Apr 25th, 2006 at 05:15 PM.

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Console app that reads/writes data files

    Easy enough. Just read from the file as you normally would and print out the data.

    Code:
    File f = new File("myfile.text");
    
    
    BufferedReader br = new BufferedReader(new FileReader(f) );
    
    String line = "";
    while ( (line = br.readLine()) != null)
    {
      System.out.println(line);
    }
    Something like that is how you read from a file. That was done off the top of my head in about 30 seconds so it may have errors.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    19

    Re: Console app that reads/writes data files

    I give up, I guess i'm far more of a java rookie then I thought I was...

    I just can't seem to put two and two together.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    19

    Re: Console app that reads/writes data files

    Am I getting anywhere here?

    Code:
    import java.io.*;
    
    public class PhoneBook
    {
       public static void main(String[] args) throws IOException
       {
    
      	 BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
    
       	//Declaring Variables
       	String InputFileName;
       	String OutputFileName;
    
       	//Get Input from User
       	System.out.print("Enter Input File Name: ");
          	InputFileName = dataIn.readLine();
       	System.out.print("\nEnter Output File Name: ");
         	 OutputFileName = dataIn.readLine();
       }
    
    
    }

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Console app that reads/writes data files

    Quote Originally Posted by Squirrel RJ
    Am I getting anywhere here?

    Code:
    import java.io.*;
    
    public class PhoneBook
    {
       public static void main(String[] args) throws IOException
       {
    
      	 BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
    
       	//Declaring Variables
       	String InputFileName;
       	String OutputFileName;
    
       	//Get Input from User
       	System.out.print("Enter Input File Name: ");
          	InputFileName = dataIn.readLine();
       	System.out.print("\nEnter Output File Name: ");
         	 OutputFileName = dataIn.readLine();
       }
    
    
    }
    I beleive, you are not going anywhere with that!

    Have you ever been asked by a computer program to enter the input or output file?
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

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



Click Here to Expand Forum to Full Width