Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 3316 | Replies: 2
![]() |
•
•
Join Date: Jul 2004
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
•
•
•
•
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;•
•
Join Date: Sep 2004
Posts: 35
Reputation:
Rep Power: 5
Solved Threads: 0
•
•
•
•
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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode