hi,
I have to write my output of a java program to a txt file.
how to do this in java
thanks
thijo 0 Newbie Poster
Recommended Answers
Jump to PostYou can use BufferedWriter to write to a file:
…FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName"); writer = new BufferedWriter(fWriter); //WRITES 1 LINE TO FILE AND CHANGES LINE writer.write("This line is written"); writer.newLine(); writer.close(); } catch (Exception e) { }
Jump to PostTake a look at the Java I/O package. I am sure it's a monster containing hundreads of classes but it present as many ways as there can be to write to a file …
Jump to PostI haven't written this kind of java code before but I am familiar with the redirect command: '>'
Maybe this is your problem:
Process p = Runtime.getRuntime().exec("java Add2number>C:\\Program Files\\Java\\jdk1.6.0_03\\bin \\out.txt");
Have you noticed a space between \\bin and \\out
...\\bin \\out
Can you try it with …
Jump to PostGood call.
I don't know if this solves the problem. We will need thijo to reply with an update of his problem
Jump to Postyou need to preappend
cmd /c
my example I tested:
package redirectconsoleoutput; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * * @author Michael */ public class Main { /** * @param args the command line arguments */ public static void main( String[] args ) { …
All 17 Replies
verruckt24 438 Posting Shark
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
thijo 0 Newbie Poster
BestJewSinceJC 700 Posting Maven
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
BestJewSinceJC 700 Posting Maven
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
thijo 0 Newbie Poster
verruckt24 438 Posting Shark
Killer_Typo 82 Master Poster
lelakijadian 0 Newbie Poster
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
Lisa1110 -2 Newbie Poster
kssk 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.