andorid socket 怎样读取接收到的文件的内容
展开全部
public void beginListen(){19 while(true){20 try{21 final Socket socket = sever.accept();22 23 new Thread(new Runnable(){24 public void run(){25 BufferedReader in;26 try{27 in = new BufferedReader(new InputStreamReader(socket.getInputStream(),"UTF-8"));28 PrintWriter out = new PrintWriter(socket.getOutputStream());29 while (!socket.isClosed()){30 String str;31 str = in.readLine();32 out.println("Hello!world!! " + str);33 out.flush();34 if (str == null || str.equals("end"))35 break;36 System.out.println(str);37 }38 socket.close();39 }catch(IOException e){40 e.printStackTrace();41 }42 }43 }).start();44 }catch(IOException e){45 e.printStackTrace();46 }47 }48 }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询