1. 使用 BufferedInputStream
public static String getBinayFile() throws IOException {
String ubjFilePath = System.getProperty("java.io.tmpdir") + File.separator + "test";
String address = "http://XXX.binayr";
byte[] data = new byte[1];
// Connect the network
URL url = new URL(address);
URLConnection conn = url.openConnection();
BufferedInputStream bufferedInputStream =
new BufferedInputStream( conn.getInputStream());
// Setting outfile
BufferedOutputStream bufferedOutputStream =
new BufferedOutputStream((new FileOutputStream(ubjFilePath)));
// Write file
while(bufferedInputStream.read(data) != -1) {
bufferedOutputStream.write(data);
}
//Output the write
bufferedOutputStream.flush();
// Close the stream
bufferedInputStream.close();
bufferedOutputStream.close();
return FilePath;
}
Reference:
http://caterpillar.onlyfun.net/Gossip/JavaGossip-V2/BufferedInOutStream.htm
http://java.sun.com/javase/6/docs/api/java/io/package-summary.html
http://my.so-net.net.tw/idealist/Java/IO.html
沒有留言:
張貼留言