Java by API/java.io/PrintStream — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 17:43, 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);
  }
}