读取本地文件上传

来源:互联网 发布:乐乎pt ipv4 编辑:程序博客网 时间:2024/06/05 22:35

Java读取本地一个文件,上传到本地另一个地方

package test;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;public class myTest {    public static void main(String[] args) throws IOException {        String loadPath = "E:/timg.jpg", outPath = "D:/uplode.jpg";        InputStream in = new FileInputStream(new File(loadPath));        FileOutputStream out = new FileOutputStream(new File(outPath));        byte[] buffer = new byte[100];// 缓存大小        int readNumber = 0;        while ((readNumber = in.read(buffer)) != -1) {            out.write(buffer, 0, readNumber);// 读取并输出buffer数组里面0~n个字节        }        in.close();        out.close();    }}
原创粉丝点击