*Stream ----- byte oriented
*der ----- char oriented
Buffered*----- add buffer
Print* ----- format
URL url = new URL(
"http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockServer.java");
URLConnection uc = url.openConnection();
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(uc.getInputStream());
out = new BufferedOutputStream(new FileOutputStream("test1"));
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
} catch (Exception ex) {
// do sth
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
本文介绍了一个使用Java实现的文件传输程序,通过URL获取远程文件,并将其保存到本地。程序中使用了BufferedInputStream和BufferedOutputStream进行流的读写操作,确保了数据的高效传输。

被折叠的 条评论
为什么被折叠?



