-4

I got problem in java. I need to use FileWriter to write output. But now i want to use Filewriter to write standard output( to console). Have any ideas?? Thanks for your helping

Duc
  • 29
  • 6

1 Answers1

3

This can be done by initializing the FileWriter with a FileDescriptor via the constructor FileWriter#FileWriter(FileDescriptor)

A quick example:

import java.io.*;

public class Test
{
    public static void main(String[] args)
    throws IOException
    {
        FileWriter fw = new FileWriter(FileDescriptor.out);
        fw.write("Hello world\n");
        fw.flush();
        fw.close();
    }
}

Outputs

Hello world