📄 process.java
字号:
package src.software0611.mxb;
import java.io.*;
import java.net.Socket;
import javax.swing.JOptionPane;
public class Process extends Thread {
Socket socket;
InputStream in;
private PrintStream out;
public final static String WEB_ROOT = "E:\\java\\WebProject\\WEB_ROOT";
public Process(Socket s) {
this.socket = s;
try {
in = socket.getInputStream();
out = new PrintStream(socket.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
public void run() {
String fileName = parse(in);
sendFile(fileName);
}
public String parse(InputStream in) {
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String fileName = null;
try {
String message = br.readLine();
String content[] = message.split("");
if (content.length != 3) {
JOptionPane.showMessageDialog(null, "文件读取错误!");
return null;
}
System.out.println("code:" + content[0] + ",fileName:" + content[1]
+ "http version:" + content[2]);
fileName = content[1];
} catch (IOException e) {
e.printStackTrace();
}
return fileName;
}
public void sendFile(String fileName) {
File file = new File(Process.WEB_ROOT + fileName);
if (!file.exists()) {
JOptionPane.showMessageDialog(null, "文件没有找到");
return;
}
try {
FileInputStream in = new FileInputStream(file);
byte contFile[] = new byte[(int) file.length()];
in.read(contFile);
out.print("文件信息");
out.write(contFile);
out.flush();
out.close();
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -