会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
spring3
博客园
首页
新随笔
联系
订阅
管理
Java例程练习(字节流)
import java.io.*; public class Test { public static void main(String[] args) { int b = 0; FileInputStream in = null; try { in = new FileInputStream("C:/java/Test.java"); } catch (FileNotFoundException e) { System.out.println("找不到指定文件"); System.exit(-1); } try { long num = 0; while((b = in.read()) != -1) { System.out.print((char)b); num ++; } in.close(); System.out.println(); System.out.println("共读取了" + num + " 个字节"); } catch (IOException e) { System.out.println("文件读取错误"); System.exit(-1); } } }
<pre name="code" class="java">import java.io.*; public class Test { public static void main(String[] args) { int b = 0; FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream("C:/java/Test.java"); out = new FileOutputStream("C:/java/A/HW.java"); while((b = in.read()) != -1) { out.write(b); } in.close(); out.close(); } catch (FileNotFoundException e) { System.out.println("找不到指定文件"); System.exit(-1); } catch (IOException e) { System.out.println("文件复制错误"); System.exit(-1); } System.out.println("文件已复制"); } }
posted @
2012-05-01 21:37
spring3
阅读(
221
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告