首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

【输入输出】读取写下文件的常用代码

2012-12-20 
【输入输出】读取写入文件的常用代码/** * 读取文件的函数 ** @param args */public static boolean readFil

【输入输出】读取写入文件的常用代码

/** * 读取文件的函数 *  * @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;}

热点排行