|
-
Apr 25th, 2006, 04:07 PM
#1
Thread Starter
Junior Member
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.
-
Apr 25th, 2006, 04:39 PM
#2
Frenzied Member
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.
-
Apr 25th, 2006, 05:44 PM
#3
Thread Starter
Junior Member
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.
-
Apr 26th, 2006, 09:58 PM
#4
Thread Starter
Junior Member
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();
}
}
-
Apr 26th, 2006, 10:50 PM
#5
Re: Console app that reads/writes data files
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|