
how to save output of java file in .txt format?

Hi,
If you are running the example from dos prompt you can use the > bracket to direct the output to a text file.
Here is the example:
C:>java MyProgram > output.txt
The output of the program will be saved into output.txt
Thanks

import java.io.FileOutputStream;
import java.io.PrintStream;
public class Redirecting extends Thread {
private int count = 1;
private int threadNumber;
private static int threadCount = 0;
public Redirecting() {
threadNumber = ++threadCount;
System.out.println("Thread: " + threadNumber + " Created.");
}
public void run() {
while (true) {
System.out.println("Thread " + threadNumber + "(" + count + ")");
if (++count == 5)
return;
}
}
public static void main(String[] args) throws Exception {
System.setOut(new PrintStream(new FileOutputStream("SystemOut.txt")));
for (int i = 0; i < 5; i++)
new Redirecting().start();
}
}
Is this code is beneficial for you. For further issues feel free to ask.
++++++ Knapster ++++++++++++
Anuj Kumar

Thanx
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.