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 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 in Java.
OR
You can use a PrintWriter over …
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 in Java.
OR
You can use a PrintWriter over an OutputStream …
Jump to PostIf you want to use that code, I'd suggest you simply copy and paste it into another file, and edit it so that it sends its output to a text file rather than prints it on the screen. You can use PrintWriter to do this.
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 …
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.