您的位置:首页 > 编程语言 > Java开发

怎样用Java实现创建文件并把文件复制到特定系统盘里

2016-10-31 14:17 375 查看
package com.zhidi;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

public class Test {

public FileInputStream fis;
public FileOutputStream fos;

public static void main(String[] args) throws IOException {

Test t = new Test();
t.create();
t.copy();

}

public void create() throws IOException{
fos = new FileOutputStream("E:\\abc.txt");
String s = "这是写入的内容";
fos.write(s.getBytes());
fos.close();
}

public void copy() throws IOException{
fis = new FileInputStream("E:\\abc.txt");
byte[] b = new byte[1024];
int len = fis.read(b);

String s = new String(b,0,len);

fos = new FileOutputStream("F:\\abc.txt");
fos.write(s.getBytes());

fos.close();
fis.close();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: