本帖最后由 杨尧 于 2012-5-23 15:29 编辑
- public class TCPServer {
- public static void main(String[] args){
- System.out.println("服务端已启动");
- ServerSocket serverSocket = null;
- try {
- serverSocket = new ServerSocket(7878);
- Socket clentSocket = serverSocket.accept();
- new Thread(new ClentRun(clentSocket));//这一行为什么会编译错误呢?纠结死我了
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if(serverSocket != null){
- try {
- serverSocket.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- }
-
- }
- public class ClentRun implements Runnable{
- Socket clent = null;
- public ClentRun(Socket clent){
- this.clent = clent;
- }
-
- public void run() {
- System.out.println(clent.getInetAddress().getHostAddress()+"连接成功");
- try {
- BufferedInputStream bis=new BufferedInputStream(clent.getInputStream());
- BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("D://2.txt"));
- PrintWriter pw=new PrintWriter(clent.getOutputStream(),true);
- int len=0;
- boolean flag = true;
- while(flag){
- System.out.println((char)len);
- bos.write(len);
- bos.flush();
- }
- pw.println("上传成功");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
复制代码 第8行为什么会编译错误呢?
这个程序可以不看别的地方,下面是我定义的一个内部类,是线程,在上面为什么不能启动呢?我还纠结,高手帮忙看看
|