本帖最后由 asinzuo 于 2015-9-8 09:40 编辑
如果文本文件内容就一行,
那么可以用Scanner读取
- Scanner sc = new Scanner(new FileInputStream("a.txt"));
-
- System.out.println(sc.nextLine());
-
- sc.close();
复制代码
如果有多行就这么读取
- Scanner sc = new Scanner(new FileInputStream("a.txt"));
- while (sc.hasNext())
- System.out.println(sc.nextLine());
- sc.close()
-
复制代码
|
|