大家帮我看下!Java

a281346230 2009-11-08 11:51:15
package c;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class TestOut {

public TestOut(){
File f1 = new File("c:\\1.txt");
File f2 = new File("c:\\2.txt");
try {
FileOutputStream fos1 = new FileOutputStream(f1);
byte buf[] = "hello".getBytes();
fos1.write(buf);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
FileInputStream fis = new FileInputStream(f1);
FileOutputStream fos2 = new FileOutputStream(f2);
int c;
while((c=fis.read())!=-1){
fos2.write(c);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}
public static void main(String[] args) {
new Test();
}

}


我想要实现的效果是

创建2个文本 1和2
1文本的内容为hello word
2文本复制1文本的内容。
前提是没有这两个文本。
不知道明白了没?
...全文
101 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jjj3751386 2009-11-08
  • 打赏
  • 举报
回复
[code=Java][g/code]
jjj3751386 2009-11-08
  • 打赏
  • 举报
回复
jf
whut0802 2009-11-08
  • 打赏
  • 举报
回复
写的很好啊,没什么问题撒,可以实现你要的功能啊
把最后一行改下,改成new TestOut()就可以了

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧