Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

redirect demo 1

 
kofi ofei
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i compile the programme there are no errors but when i run it nothing appears to be happening

import java.io.*;

public class RedirectDemo1{
public static void main(String args[]) throws IOException {

// set up a PrintStream pointing at a file

FileOutputStream fos =
new FileOutputStream("out.txt");
BufferedOutputStream bos =
new BufferedOutputStream(fos, 1024);
PrintStream ps =
new PrintStream(bos, false);

// redirect System.out to it

System.setOut(ps);

// do some output

System.out.println("This is a test\u4321");
int n = 37;
System.out.println("The square of " + n + " is " + (n * n));

ps.close();
}
}
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check the file?

Moving to JIG (beginner) forum.

Mark
 
kofi ofei
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah
 
Marco Davids II
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i ran your code as is and it seemed to work fine ...
what errors are you getting ?
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic