First: import java.io.*;
Then you need to read from the console:
try
{
//create a buffered reader that connects to the console, we use it so we can read lines
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//read a line from the console
String lineFromInput = in.readLine();
//create an print writer for writing to a file
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
//output to the file a line
out.println(lineFromInput);
//close the file (VERY IMPORTANT!)
out.close();
}
catch(IOException e)
{
System.out.println("Error during reading/writing");
}
If you need more programming help visit or email me at
NPH
Junior Poster in Training
55 posts since May 2005
Reputation Points: 10
Solved Threads: 1
>is it possible to type in a class as a .txt file and then print out:
You better explain what you mean by this. To help you here is few examplesget user input from console and then store it in file
get user input through some Swing components and store it in the file
read another file and either store it all or just part of it in new file
PS: You should post your code so we can see what you actualy trying to do. Please use code tags to post any code.
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
java DooBee
at the cmd to "run" the file .class
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
hi,
i was trying to contact to at needprogramminghelp but the mail delivery failed.
can i have ur ID to contact you?
regards
That was all junk that slipped by attention of moderators in the pass. Why did you wanted to contact somebody who obviously deleted that account and website is dead as some marketing company has some rubbish on it?
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
i wanted to discuss some problems that i am facing in java thats why, can u suggest me any person from java community?
You are already in Java community! So why don't you create new thread and post your question?
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902