?? getfile.java
字號:
import java.net.*;
import java.io.*;
import java.util.zip.GZIPInputStream;
public class GetFile{
int port=2345; //端口號
String host="localhost"; //服務器地址
Socket socket; //客戶端套接字
public GetFile(){
try{
socket=new Socket(InetAddress.getByName(host),port); //實例化套按字
DataInputStream in=new DataInputStream(socket.getInputStream()); //得到輸入流
GZIPInputStream gin=new GZIPInputStream(in); //壓縮輸入流
FileOutputStream fileOut=new FileOutputStream("e:/2.txt"); //文件輸出流
byte[] buffer=new byte[1024]; //緩沖區
int length;
while ((length=gin.read(buffer))!=-1){ //讀取數據
fileOut.write(buffer,0,length); //寫入數據到文件
}
System.out.println("Received Success!");
gin.close(); //關閉輸入流
socket.close(); //關閉套接字
fileOut.close(); //關閉輸出流
}
catch (IOException ex){
ex.printStackTrace(); //輸出錯誤信息
}
}
public static void main(String[] args){
new GetFile();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -