【输入输出】读取写入文件的常用代码
/** * 读取文件的函数 * * @param args */public static boolean readFile() {try {Scanner input = new Scanner(new File("input.txt"));n = input.nextInt();k = input.nextInt();oil = n;nextOil = new int[k + 1];for (int i = 0; i <= k; i++) {nextOil[i] = input.nextInt();}} catch (FileNotFoundException e) {System.out.println("读取文件出错");return false;}return true;}public static boolean writeFile(String s) {// 输出部分try {Formatter output = new Formatter("output.txt");output.format(s);output.close(); // 一定要写,不写就输不出来} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();return false;}return true;}