Java by API/java.io/PrintStream — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:32, 31 мая 2010
Содержание
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);
}
}