[转帖]JAVA IO经典文件操作例子,你会发现IO是如此简单【1】_Android, Python及开发编程讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Android, Python及开发编程讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 3172 | 回复: 0   主题: [转帖]JAVA IO经典文件操作例子,你会发现IO是如此简单【1】        下一篇 
lengyuLee
注册用户
等级:少校
经验:1118
发帖:83
精华:5
注册:2013-3-7
状态:离线
发送短消息息给lengyuLee 加好友    发送短消息息给lengyuLee 发消息
发表于: IP:您无权察看 2013-3-12 11:10:51 | [全部帖] [楼主帖] 楼主

IO是JAVASE中非常重要的一块,是面向对象的完美体现,深入学习IO,你将可以领略到很多面向对象的思想。

在公司没活干,复习了一下IO,发现很多都忘记了,所以写的不好,只够初学用。我把我复习过程中写的代码贴出来,大家共同学习,并请多指教指教哈。顺便一起讨论IO

1、文件拷贝

Java code
?




1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25


try {

File inputFile = new File(args[0]);

if (!inputFile.exists()) {

System.out.println("源文件不存在,程序终止");

System.exit(1);

}

File outputFile = new File(args[1]);

InputStream in = new FileInputStream(inputFile);

OutputStream out = new FileOutputStream(outputFile);

byte date[] = new byte[1024];

int temp = 0;

while ((temp = in.read(date)) != -1) {

out.write(date);

}

in.close();

out.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


该贴被lengyuLee编辑于2013-3-12 11:15:29




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论