First of all, don't reinitialize the PrintStream object in every loop iteration.
To write to a file, simply call PrintStream's println method. You may not realise it, but when you print to the console, this is exactly what you are doing. System.out is a PrintStream object.
PrintStream out =
new PrintStream(new File("stuff.txt"));
while (in.hasNext()) {
String word = in.next();
out.println(convert(word));
}
Answer from Jade on Stack OverflowFirst of all, don't reinitialize the PrintStream object in every loop iteration.
To write to a file, simply call PrintStream's println method. You may not realise it, but when you print to the console, this is exactly what you are doing. System.out is a PrintStream object.
PrintStream out =
new PrintStream(new File("stuff.txt"));
while (in.hasNext()) {
String word = in.next();
out.println(convert(word));
}
import java.io.PrintStream;
public class Main2{
public static void main(String[]args){
String str = " The Big House is";
PrintStream ps = new PrintStream(System.out);
ps.printf("My name is : %s White", str);
ps.flush();
ps.close();
}
}
Output is : The Big House is White
The other way to use PrintStream is...
CharSequence cq = "The Big House is White";
PrintStream ps = new PrintStream(System.out);
ps.append(cq);
ps.flush();
ps.close();
}
}
Videos
What are all the way to print out things to a console in Java (well, all the basic ones).
For example, I know:
System.out.println("Text" +something);
What are other basic ones and how are they different (including the above)? The only thing I understand about the above is that it prints things to the screen. Also, please be sure to do the capitalizations correctly as that is something I'm trying to make sure I get correct as well.