package commi;
import java.io.*;
import java.net.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.File;
import java.awt.*;
public class UseCaseServer extends JFrame implements Runnable{
protected JTextArea textArea;
protected Socket socket;
protected DataInputStream input;
protected DataOutputStream output;
protected ServerSocket server;
protected File file;
public UseCaseServer(){
Container cp = getContentPane();
textArea = new JTextArea();
cp.add(textArea);
Thread thread = new Thread();
thread.start();
setTitle("服务器端");
setSize(600,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void run(){
try{
file = new File("");
System.out.println("已连接服务器");
server = new ServerSocket(8000);
socket = server.accept();
input = new DataInputStream( socket. getInputStream());
output = new DataOutputStream(socket.getOutputStream());
file = new File("input.readUTF()");
// str = getAbsolutePath(inStr);
if(file.exists()){
FileInputStream in = new FileInputStream(file);
byte byt[] = new byte[1024];
output.writeUTF(new String(byt));
textArea.append("byt");
in.close();
}
else{
output.writeUTF("对不起没有你要找的文件");
System.out.println("对不起没有你要找的文件");
}
}catch(IOException e){
e.printStackTrace();
}
}
public static void main(String[] args){
new UseCaseServer();
}
}
问题是好像线程没启动,run()方法里的语句没有执行啊。
import java.io.*;
import java.net.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.File;
import java.awt.*;
public class UseCaseServer extends JFrame implements Runnable{
protected JTextArea textArea;
protected Socket socket;
protected DataInputStream input;
protected DataOutputStream output;
protected ServerSocket server;
protected File file;
public UseCaseServer(){
Container cp = getContentPane();
textArea = new JTextArea();
cp.add(textArea);
Thread thread = new Thread();
thread.start();
setTitle("服务器端");
setSize(600,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void run(){
try{
file = new File("");
System.out.println("已连接服务器");
server = new ServerSocket(8000);
socket = server.accept();
input = new DataInputStream( socket. getInputStream());
output = new DataOutputStream(socket.getOutputStream());
file = new File("input.readUTF()");
// str = getAbsolutePath(inStr);
if(file.exists()){
FileInputStream in = new FileInputStream(file);
byte byt[] = new byte[1024];
output.writeUTF(new String(byt));
textArea.append("byt");
in.close();
}
else{
output.writeUTF("对不起没有你要找的文件");
System.out.println("对不起没有你要找的文件");
}
}catch(IOException e){
e.printStackTrace();
}
}
public static void main(String[] args){
new UseCaseServer();
}
}
问题是好像线程没启动,run()方法里的语句没有执行啊。
Thread thread = new Thread(new UseCaseServer());
thread.start();
}