RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 3316 | Replies: 2
Reply
Join Date: Jul 2004
Posts: 6
Reputation: macca1979 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
macca1979 macca1979 is offline Offline
Newbie Poster

writing to a file

  #1  
Sep 2nd, 2004
Hey there,

I'm new to java and I need to write a string that i generated in my code to an output file. I'm currently writing the string to the standard output like so :

System.out.println("K_"+Receiver+",t"+msgnum+"(R("
+Receiver+",t"+msgnum+"("+out1+")))");

All the types e.g. 'Receiver' or 'out1' are of type string. Could anyone show me how to open a file for writing and then write this information to the file? Is there some sort of file writer equivalent for system.out.println()? Thanks very much
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2004
Location: Pakistan
Posts: 1,673
Reputation: nanosani is an unknown quantity at this point 
Rep Power: 8
Solved Threads: 49
Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: writing to a file

  #2  
Sep 3rd, 2004
Originally Posted by macca1979
Hey there,

I'm new to java and I need to write a string that i generated in my code to an output file. I'm currently writing the string to the standard output like so :

System.out.println("K_"+Receiver+",t"+msgnum+"(R("
+Receiver+",t"+msgnum+"("+out1+")))");

All the types e.g. 'Receiver' or 'out1' are of type string. Could anyone show me how to open a file for writing and then write this information to the file? Is there some sort of file writer equivalent for system.out.println()? Thanks very much

You can read about File streams of java :
Anywayz I give you some code ... You have to write exceptions yourself:

String s ="this is the string you want to write to the file.";
File name = new File("sani.txt");
FileWriter fw = new FileWriter(name);
fw.write(s);
fw.close;
Reply With Quote  
Join Date: Sep 2004
Posts: 35
Reputation: tigerxx is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
tigerxx tigerxx is offline Offline
Light Poster

Re: writing to a file

  #3  
Sep 27th, 2004
Originally Posted by macca1979
Hey there,

I'm new to java and I need to write a string that i generated in my code to an output file. I'm currently writing the string to the standard output like so :

System.out.println("K_"+Receiver+",t"+msgnum+"(R("
+Receiver+",t"+msgnum+"("+out1+")))");

All the types e.g. 'Receiver' or 'out1' are of type string. Could anyone show me how to open a file for writing and then write this information to the file? Is there some sort of file writer equivalent for system.out.println()? Thanks very much

u can use PrintStream out = new PrintStream(new OutputStream(new FileOutputStream(new File("Name of ur file"))));
now u can use same line for wrting into file
like this
out.println("K_"+Receiver+",t"+msgnum+"(R("
+Receiver+",t"+msgnum+"("+out1+")))");

it will write to the file don't forgot to import import java.io.*;
if any doubts please revert
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:54 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC