java读取文件流和写入

package jsoup;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.io.FileUtils;

public class Test {

public static void main(String[] args) throws MalformedURLException, IOException {
Map<Integer, String> map = new HashMap<Integer,String>();


String path = "http://files.eduuu.com/img/2014/12/04/170859_548024abcf1bf.png";
String destFile = "d://"+UUID.randomUUID()+".png";
FileUtils.copyURLToFile(new URL(path), new File(destFile));
/*OutputStream os = new FileOutputStream(new File(destFile));
byte[] b = new byte[1024];
try {
InputStream is = new URL(path).openStream();
while (is.read(b) != -1) {
os.write(b);
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
*/


}

}

posted @ 2017-02-23 15:29  祥福有梦想  阅读(5318)  评论(0编辑  收藏  举报