📄 networking2.java
字号:
package cc;
import java.applet.*;
import java.io.*;
import java.net.*;
public class Networking2 {
public static void main(String[] args) {
try {
//URL url = new URL(new Constants().geturl());
URL url = new URL("http://www.daqiancn.com/images/解脱.MP3 ");
// URL url2 = new URL("http://www.sjtu.edu.cn/down.zip");
// HttpURLConnection httpConnection = (HttpURLConnection)url2.openConnection();
// 设置User-Agent
// httpConnection.setRequestProperty("User-Agent","NetFox");
// 设置断点续传的开始位置
// httpConnection.setRequestProperty("RANGE","bytes=2000070");
// 获得输入流
// InputStream input1 = httpConnection.getInputStream();
//URLConnection con = url2.openConnection();//.connect();
HttpURLConnection con=(HttpURLConnection) url.openConnection();
con.connect();
float filelength=con.getContentLength();
float a=filelength/(1024*1024);
// final GetMethod get = new GetMethod(url);
// long size = get.getResponseContentLength();
System.out.println(a+"M");
BufferedInputStream input = new BufferedInputStream(con.getInputStream());
File f = new File("d:/jifdetuo.mp3");
//File f = new File(new Constants().getpath());
//FileOutputStream output = new FileOutputStream(f);
RandomAccessFile out=new RandomAccessFile(f,"rw");
//BufferedOutputStream boutput = new BufferedOutputStream(new FileOutputStream(f));
int data = 0;
/*
* while(input.read()!=-1){
boutput.write((byte) data);
}
*/
while (true) {
data = input.read();
if (data == -1)
{
System.out.println("文件下载完成");
break;
}
//System.out.print((char)data);
out.write((byte) data);
}
// System.out.println("文件下载完成");
//out.flush();
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -