PDA

Click to See Complete Forum and Search --> : Console app that reads/writes data files


Squirrel RJ
Apr 25th, 2006, 04:07 PM
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

System_Error
Apr 25th, 2006, 04:39 PM
Easy enough. Just read from the file as you normally would and print out the data.



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.

Squirrel RJ
Apr 25th, 2006, 05:44 PM
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.

Squirrel RJ
Apr 26th, 2006, 09:58 PM
Am I getting anywhere here?

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


}

ComputerJy
Apr 26th, 2006, 10:50 PM
Am I getting anywhere here?

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?