Redirecting console output to file

Reply

Join Date: May 2005
Posts: 1
Reputation: ghfeyn is an unknown quantity at this point 
Solved Threads: 0
ghfeyn ghfeyn is offline Offline
Newbie Poster

Redirecting console output to file

 
0
  #1
May 19th, 2005
Hi everyone,

I am having trouble with getting output from the console onto a file, for example a .TXT. I suspect that I have to make use of the System.out function, but I can't quite figure out how I might use it. Thanks for the help
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 30
Reputation: yassar is an unknown quantity at this point 
Solved Threads: 0
yassar's Avatar
yassar yassar is offline Offline
Light Poster

Re: Redirecting console output to file

 
0
  #2
May 19th, 2005
You can use " java.io" package classes to do that.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 55
Reputation: NPH is an unknown quantity at this point 
Solved Threads: 1
NPH NPH is offline Offline
Junior Poster in Training

Re: Redirecting console output to file

 
0
  #3
May 19th, 2005
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 www.NeedProgrammingHelp.com or email me at NeedProgrammingHelp@hotmail.com
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 6
Reputation: CAESARIO is an unknown quantity at this point 
Solved Threads: 0
CAESARIO's Avatar
CAESARIO CAESARIO is offline Offline
Newbie Poster

Re: Redirecting console output to file

 
0
  #4
Jun 17th, 2008
is it possible to type in a class as a .txt file and then
print out:


system.out.println "this is true"

as This is true on the cmd???

tell me how please..

my books have given progs to write nad see output and i can't see output althougt all progs are running and compling...

thanks in advance!!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,185
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 482
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Redirecting console output to file

 
0
  #5
Jun 17th, 2008
>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 examples
  • get 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.
Last edited by peter_budo; Jun 17th, 2008 at 4:15 am. Reason: typo
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 6
Reputation: CAESARIO is an unknown quantity at this point 
Solved Threads: 0
CAESARIO's Avatar
CAESARIO CAESARIO is offline Offline
Newbie Poster

Re: Redirecting console output to file

 
0
  #6
Jun 17th, 2008
Hi,,

what i meant was... I have written out a class in a .txt file...
I got a portion that said:
{
System.out.println"this is true";
}

Now i compiled my program on my cmd, and get the .class file in my folder in C drive.

I want to see the out put of my program on my cmd screen.... I want to see

"this is true"
written out theere...

and i don' tknow how.

I write :
javac DooBee.java ->it gets compiled and i get my DooBee.class file.

but now how do i get to see my sentence written out where i wanted it to print?
I want to see the output of the class i wrote to see if my program was not only compiled right but can make some sense to mee too!

this is my program.:

class DooBee
{
public static void main (String args[] )
{
int x=1;
while (x<3)
{
System.out.print("Doo");
System.out.print("Bee");
x=x+1;
}
if(x==2)
System.out.print("Do");
}
}




I hope this is clearer.

Thanks
Last edited by CAESARIO; Jun 17th, 2008 at 9:31 am. Reason: incomplete message.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,649
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 223
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Redirecting console output to file

 
0
  #7
Jun 17th, 2008
java DooBee
at the cmd to "run" the file .class
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 6
Reputation: CAESARIO is an unknown quantity at this point 
Solved Threads: 0
CAESARIO's Avatar
CAESARIO CAESARIO is offline Offline
Newbie Poster

Re: Redirecting console output to file

 
0
  #8
Jun 17th, 2008
Exception in thread "main" java.lang.NoClassDefFoundError: DooBee


this is what i got.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,438
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Redirecting console output to file

 
0
  #9
Jun 17th, 2008
You need to start with the most basic "getting started" tutorial: http://java.sun.com/docs/books/tutor...ava/win32.html

And do not post new questions to the end of other people's old threads. Post a new thread of your own if you have a question.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC