I am doing data analysis using hadoop using java on eclipse ,I am get my output log as shown in the below image on eclipse, how can we redirect it to a text area..
Asked
Active
Viewed 491 times
3 Answers
0
Try this:
public class JTextAreaOutputStream extends OutputStream {
private JTextArea destination;
public JTextAreaOutputStream(JTextArea destination) {
if (destination == null)
throw new IllegalArgumentException ("Destination is null");
this.destination = destination;
}
@Override
public void write(int b) throws IOException {
write (new byte [] {(byte)b}, 0, 1);
}
@Override
public void write(byte[] buffer, int offset, int length) throws IOException
{
final String text = new String (buffer, offset, length);
SwingUtilities.invokeLater(new Runnable ()
{
@Override
public void run()
{
destination.append (text);
}
});
}
}
Then Redirect you text area like this:
public void setSystemOutRedirect() {
JTextAreaOutputStream out = new JTextAreaOutputStream (textAreaUpgraderLog);
System.setOut (new PrintStream(out));
System.setErr(new PrintStream(out));
}

Salah
- 8,567
- 3
- 26
- 43
-
I am not giving the output they are generated automatically, so it doesnt help – vakul Feb 10 '14 at 15:40
-
1its only printing the data i.e given by me in system.out.print() i want the log file to be printed.. – vakul Feb 10 '14 at 15:58
0
Just use the following snippet at the beginning of your program.
File file = new File("D:/out.txt");
FileOutputStream fos = new FileOutputStream(file);
PrintStream ps = new PrintStream(fos);
System.setErr(ps);
then all Standard err will be redirected to D:/out.txt
file.
For redirecting standard output just use System.setOut(ps)

Tom Sebastian
- 3,373
- 5
- 29
- 54
0
These are mostly counters and progress so, have a look at this post and JobClient's API.
Also, I think you will find this post very useful.