📄 driver.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -