import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class FileUtiles{
public static void upload(File file,String path) throws Exception{
InputStream is = new FileInputStream(file);
upload(is,path);
}
public static void upload(InputStream is,String path) throws Exception{
OutputStream os = null ;
try{
os = new FileOutputStream(path);
int length = -1;
byte[] buffer = new byte[7092];
//从输入流中读取一定数量的字节,并将其存储在缓冲区数组buffer中。
//以整数形式返回实际读取的字节数.
//在输入数据可用、检测到文件末尾或者抛出异常前,此方法一直阻塞。
//如果buffer的长度为 0,则不读取任何字节并返回 0;
//否则,尝试读取至少一个字节.
//如果因为流位于文件末尾而没有可用的字节,则返回值-1;
//否则,至少读取一个字节并将其存储在buffer中。
//将读取的第一个字节存储在元素 buffer[0]中,下一个存储在buffer[1]中,依次类推.
//读取的字节数最多等于buffer的长度。设length为实际读取的字节数;
//这些字节将存储在buffer[0]到buffer[length-1]的元素中,
//不影响length[k]到length[b.length-1]的元素.
while(-1!=(length = is.read(buffer,0,7092))){
os.write(buffer,0,length);
}
}catch(Exception e){
e.printStackTrace();
}
finally{
if(null != is){
is.close();
}
if(null != os){
os.close();
}
}
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class FileUtiles{
public static void upload(File file,String path) throws Exception{
InputStream is = new FileInputStream(file);
upload(is,path);
}
public static void upload(InputStream is,String path) throws Exception{
OutputStream os = null ;
try{
os = new FileOutputStream(path);
int length = -1;
byte[] buffer = new byte[7092];
//从输入流中读取一定数量的字节,并将其存储在缓冲区数组buffer中。
//以整数形式返回实际读取的字节数.
//在输入数据可用、检测到文件末尾或者抛出异常前,此方法一直阻塞。
//如果buffer的长度为 0,则不读取任何字节并返回 0;
//否则,尝试读取至少一个字节.
//如果因为流位于文件末尾而没有可用的字节,则返回值-1;
//否则,至少读取一个字节并将其存储在buffer中。
//将读取的第一个字节存储在元素 buffer[0]中,下一个存储在buffer[1]中,依次类推.
//读取的字节数最多等于buffer的长度。设length为实际读取的字节数;
//这些字节将存储在buffer[0]到buffer[length-1]的元素中,
//不影响length[k]到length[b.length-1]的元素.
while(-1!=(length = is.read(buffer,0,7092))){
os.write(buffer,0,length);
}
}catch(Exception e){
e.printStackTrace();
}
finally{
if(null != is){
is.close();
}
if(null != os){
os.close();
}
}
}
}