会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
spring3
博客园
首页
新随笔
联系
订阅
管理
java例程练习(缓冲流)
import java.io.*; public class Test { public static void main(String[] args) { try { FileInputStream fis = new FileInputStream("C:/java/Test.java"); BufferedInputStream bis = new BufferedInputStream(fis); int c = 0; System.out.println(bis.read()); System.out.println(bis.read()); bis.mark(100); for(int i = 0; i <= 10 && (c = bis.read()) != -1; i++) { System.out.print(c+ " "); } System.out.println(); bis.reset(); for(int i = 0; i <= 10 &&(c = bis.read()) != -1; i++) { System.out.print(c + " "); } bis.close(); } catch (FileNotFoundException e) { System.out.println("文件不存在"); } catch (IOException e) { System.out.println("读取异常"); } } }
import java.io.*; public class TTest { public static void main(String[] args) { try { BufferedWriter bw = new BufferedWriter(new FileWriter("C:/java/Test_Bak.txt")); BufferedReader br = new BufferedReader(new FileReader("C:/java/Test.java")); String s = null; for(int i = 0; i <= 100; i++) { s = String.valueOf(Math.random()); bw.write(s); bw.newLine(); } bw.flush(); while((s = br.readLine()) != null) { System.out.println(s); } bw.close(); br.close(); } catch (FileNotFoundException e) { System.out.println("文件不存在"); } catch (IOException e) { System.out.println("读取异常"); } } }
posted @
2012-05-02 16:59
spring3
阅读(
354
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告