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

来源:互联网 发布:origin for mac 编辑:程序博客网 时间:2024/05/21 16:12
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();
}


}
0 0