首页 > 代码库 > ...............
...............
public class TestCopyArray {
public static void main(String[] args) throws Exception {
InputStream is = new FileInputStream("第10章/a.txt");
OutputStream os = new FileOutputStream("第10章/b.txt");
byte[] bs = new byte[1024];
while(true){
int length = is.read(bs);
//从下标0开始,把length长度写到文件中
os.write(bs,0,length);
if(length<1024){
break;
}
}
is.close();
os.close();
}
}
注意:a.boolean:表示是否向文件末尾追加,如果是true表示追加,false表示不追加(也就是覆盖),默认值是false;
b.创建FileOutputStream实例时,如果相应的文件并不存在,则会自动创建一个空的文件。
...............
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。