本帖最后由 H07000223 于 2012-3-2 19:08 编辑
- public static void main(String[] args) throws Exception
- {
- //写
- FileOutputStream fos=new FileOutputStream("file.txt");
-
- OutputStreamWriter osw=new OutputStreamWriter(fos);
-
- BufferedWriter bw=new BufferedWriter(osw);
-
- bw.write("hello\n");
- bw.write("world\n");
- bw.write("welcome!");
-
- bw.close();
-
- //读
- FileInputStream fis=new FileInputStream("file.txt");
-
- InputStreamReader isr=new InputStreamReader(fis);
-
- BufferedReader br=new BufferedReader(isr);
-
- System.out.println(br.readLine());//第一行
- System.out.println(br.readLine());//第二行
- System.out.println(br.readLine());//第三行
-
- String str="";
-
- while(null!=(str=br.readLine()))
- {
- System.out.println(str);
- }
-
- br.close();
- }
复制代码 用了两种方式打印:只得到了一次结果。。。 |
|