标签:eof 系统信息 demo read nbsp except spec [] util
static void setIn(InputStream in) Reassigns the "standard" input stream.
static void setOut(PrintStream out) Reassigns the "standard" output stream.
package bxd; import java.io.*; public class TransStreamDemo3 { public static void main(String[] args) throws IOException { // 并不常用 System.setIn(new FileInputStream("s.txt")); System.setOut(new PrintStream("out.txt")); BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufw = new BufferedWriter(new OutputStreamWriter(System.out)); String line; while ((line = bufr.readLine()) != null) { if ("eof".equals(line)) break; bufw.write(line); bufw.newLine(); bufw.flush(); } bufr.close(); bufw.close(); } }
void printStackTrace(PrintStream s) Prints this throwable and its backtrace to the specified print stream.
package bxd; import java.io.PrintStream; import java.text.SimpleDateFormat; import java.util.Date; public class ExceptionInfo { public static void main(String[] args) { try { // 数组越界访问 int[] array = new int[2]; System.out.println(array[3]); } catch (Exception e) { PrintStream printStream = null; String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); try { printStream = new PrintStream("ExceptionInfo.txt"); printStream.println(time); //printStream.write(time.getBytes()); } catch (Exception ex) { throw new RuntimeException("日志文件创建失败"); } e.printStackTrace(printStream); } // 实际项目中会使用log4j. } }
static Properties getProperties() Determines the current system properties.
package bxd; import java.io.IOException; import java.io.PrintStream; import java.util.Properties; public class SystemInfo { public static void main(String[] args) throws IOException { Properties prop = System.getProperties(); prop.list(new PrintStream("Sysinfo.txt")); } }
标签:eof 系统信息 demo read nbsp except spec [] util
原文地址:http://www.cnblogs.com/echo1937/p/6357634.html