driver.java
来自「Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套」· Java 代码 · 共 53 行
JAVA
53 行
import java.io.*;import java.util.Scanner;/** Program to write to a new binary file and read from it using Scanner (end of Section 13.6) * Author: David Riley * Date: January, 2005 */public class Driver { public Driver() { try { FileOutputStream outStream; PrintWriter printWriter; outStream = new FileOutputStream( "example.txt" ); printWriter = new PrintWriter( outStream ); printWriter.print( 12+" " ); printWriter.print( true+" " ); printWriter.println( 98.7+" " ); printWriter.println( "hello world" ); printWriter.println('Z'); printWriter.flush(); printWriter.close(); } catch (IOException e) { System.out.println("ERROR writing." ); } try { FileInputStream inStream; Scanner inScan; inStream = new FileInputStream( "example.txt" ); inScan = new Scanner( inStream ); while ( inScan.hasNext() ) { if (inScan.hasNextBoolean()) System.out.println( "Boolean value: " + inScan.nextBoolean()); else if (inScan.hasNextLong()) System.out.println( "Integer value: " + inScan.nextLong()); else if (inScan.hasNextDouble()) System.out.println( "Double value: " + inScan.nextDouble()); else // it must be a String System.out.println( "String value: " + inScan.next()); } inScan.close(); } catch (IOException e) { System.out.println("ERROR reading." ); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?