java读取文件流和写入

时间:2023-01-29 20:59:32

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();
}
*/


}

}