Java by API/java.io/PrintStream
Содержание
new PrintStream(File file)
import java.io.File;
import java.io.PrintStream;
public class Main {
public static void main(String[] args) throws Exception {
File file = new File("C:\\a.txt");
PrintStream ps = new PrintStream(file);
System.setOut(ps);
System.out.println("To File");
}
}
new PrintStream(OutputStream out)
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
public class MainClass {
public static void main(String[] args) {
try {
File tempFile = File.createTempFile("myfile", ".tmp");
FileOutputStream fout = new FileOutputStream(tempFile);
PrintStream out = new PrintStream(fout);
out.println("some text");
} catch (IOException ex) {
System.out.println("There was a problem creating/writing to the temp file");
ex.printStackTrace();
}
}
}
PrintStream: print(char c)
public class Main {
public static void main(String[] args) {
System.out.print(12);
System.out.print("g");
}
}
PrintStream: print(int i)
public class Main {
public static void main(String[] args) {
System.out.print(12);
System.out.print("g");
}
}
PrintStream: print(String s)
public class Main {
public static void main(String[] args) {
String message = "qwer";
System.out.print(message);
}
}