package FSOperation;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
public class MyMain {
public static void main(String[] args){
File file = new File("D:/a.txt");
try {
FileInputStream fileInput = new FileInputStream(file);
FileChannel fileInputChannel = fileInput.getChannel();
ByteBuffer bytebuffer = fileInputChannel.map(MapMode.READ_ONLY, 0, file.length());
FileOutputStream fileOutput =new FileOutputStream("D:/b.txt");
FileChannel fileOutputChannel = fileOutput.getChannel();
fileOutputChannel.write(bytebuffer);
bytebuffer.clear();
fileInputChannel.close();
fileOutputChannel.close();
System.out.println(System.getProperties());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch(IOException e){
}
}
}
运行结果:
将a.txt 里面的内容写到了b.txt 里面