public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new StringReader(BufferedInputFile.read("FileOutputShortcut.java"))); // Here's the shortcut: PrintWriter out = new PrintWriter(file); int lineCount = 1; String s; while ((s = in.readLine()) != null) out.println(lineCount++ + ": " + s); out.close(); // Show the stored file: System.out.println(BufferedInputFile.read(file)); }
public static void main(String[] args) throws IOException { DataInputStream in = new DataInputStream( new ByteArrayInputStream(BufferedInputFile.read("test.txt").getBytes())); while (in.available() != 0) { // available()方法查看还有多少个可供存取的字符 System.out.println((char) in.readByte()); } }