我这个是移动图片的。有读取流,输出流的方式:package org.example.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class TestIOStream {
/**
*
* DOC 将F盘下的test.jpg文件,读取后,再存到E盘下面.
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
FileInputStream in = new FileInputStream(new File("F:\\test.jpg"));// 指定要读取的图片
File file = new File("E:\\test.jpg");
if (!file.exists()) {// 如果文件不存在,则创建该文件
file.createNewFile();
}
FileOutputStream out = new FileOutputStream(new File("E:\\test.jpg"));// 指定要写入的图片
int n = 0;// 每次读取的字节长度
byte[] bb = new byte[1024];// 存储每次读取的内容
while ((n = in.read(bb)) != -1) {
out.write(bb, 0, n);// 将读取的内容,写入到输出流当中
}
out.close();// 关闭输入输出流
in.close();
}
}