使用字节流将图片上传至给定的文件夹
package com.hp.Test;
import java.io.*;
public class Demo1 {
public static void main(String[] args) throws IOException {
File file = new File(“D:\MobileFile\1.jpeg”);
//通过字节输入流读取该文件
InputStream is = new FileInputStream(file);
//通过字节输出流给OutputStream准确的需要保存的位置
OutputStream os = new FileOutputStream(“D:\Qs\1.jpeg”);
//添加对应的读取容器,以字节存储
byte[] buffer = new byte[1024];
int length = 0;
while((length = is.read(buffer)) > -1){
os.write(buffer,0,length);
}
is.close();
os.close();
}
}