package com.baoyi.MyTest;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class StreamTest {
private InputStream in = null;
private OutputStream out = null;
private final static int BUFFER_SIZE = 16 * 1024;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File Infile = new File(
"C:/Documents and Settings/All Users/Documents/My Pictures/213213.jpg");
File Outfile = new File("D:/dd.jpg");
InputStream in = null;
OutputStream out = null;
System.out.print(Infile.length());
try {
if (Infile.length() < 1024 * 1024 * 5) {
System.out.print(Infile.length());
in = new BufferedInputStream(new FileInputStream(Infile),
BUFFER_SIZE);
out = new BufferedOutputStream(new FileOutputStream(Outfile),
BUFFER_SIZE);
byte[] buffer = new byte[BUFFER_SIZE];
while (in.read(buffer) > 0) {
out.write(buffer);
}
System.out.print("图片上传!");
} else {
System.out.print("图片没有上传!");
}
} catch (Exception e) {
// TODO: handle exception
System.out.print("图片上传出错!" + e.getMessage());
}
}
}
流的方式上传文件
最新推荐文章于 2021-08-06 16:00:51 发布