File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes a question about a program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "a question about a program " Watch "a question about a program " New topic
Author

a question about a program

alan fisher
Greenhorn

Joined: Sep 27, 2003
Posts: 5
import java.io.*;
public class ChangeSystemOut {
public static void main(String[] args) {
PrintWriter out =
new PrintWriter(System.out,true);
out.println("Hello, world");
}
} ///:~
It's a program from <Thinking in java>.
When I use PringWriter(System.out),there's no result.why?
K Robert
Ranch Hand

Joined: May 16, 2003
Posts: 116
import java.io.*;
public class ChangeSystemOut {
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out,true);
out.println("Hello, world");
}
}
Tested and it works... Not sure why it's not working for you. What are the error meesages?
It would be easier to do it this way:
public class ChangeSystemOut {
public static void main(String[] args) {
System.out.println("Hello, world");
}
}
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104
When I use PringWriter(System.out),there's no result.why?

Hi Ken,
I think alan is asking about another constructor which takes only one argument as System.out. Pls check the below code.


Anbudan & Mahalo,<br />Arul<br /> <br />-Not a sun certified Java professional :-)
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Add an out.flush() - the PrintWriter may buffer output for performance reasons - flush is taking care of writing the buffer to the actual output target, as is setting the autoflush property to true.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104
Hi alan fisher,
Please check the code below. that works fine after adding the flush().
Thanks folks..
import java.io.*;
public class ChangeSystemOut
{
public static void main(String[] args)
{
PrintWriter out = new PrintWriter(System.out,true);
out.println("Hello, world"); //This is printed
PrintWriter out1 = new PrintWriter(System.out);
out1.println("Hello, world1"); //This is also getting printed after using flush()
out1.flush();
}
} ///:~
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a question about a program
 
Similar Threads
System.out ?
system.out.println query
small IO problem
why String vlass reference variable holds content ?
QuizCard txt file - newline missing