尝试通过Android Studio中的TCP套接字发送文件时,FileNotFoundException(权限被拒绝)

时间:2018-03-05 19:06:32

标签: java android tcp server permissions

我正在尝试通过TCP套接字将音频文件发送到计算机上的客户端。调用Server函数时,它会连接到套接字,但会抛出FileNotFoundException并拒绝权限。我在清单中拥有所有必需的权限,而且我真的不知道自己缺少什么。



public class Server extends AsyncTask < File, Void, Void > {

  public Void doInBackground(File...soundFile) {

    System.out.println("server: " + soundFile);

    try (ServerSocket serverSocket = new ServerSocket(6669); FileInputStream in = new FileInputStream(soundFile[0])) {
      if (serverSocket.isBound()) {
        Socket sender = serverSocket.accept();
        OutputStream out = sender.getOutputStream();

        byte buffer[] = new byte[2048];
        int count;
        while ((count = in .read(buffer)) != -1)
          out.write(buffer, 0, count);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    System.out.println("server: shutdown");
    return null;
  }
}
&#13;
&#13;
&#13;

在我的MainActivity中调用Server方法。

&#13;
&#13;
Uri Selected = data.getData();
            wholepath = getRealPathFromURI(Selected);
            Toast.makeText(this, wholepath, Toast.LENGTH_LONG).show();
            try{
                File file = new File(wholepath);
                new Server().execute(file);
            } catch (Exception e) {
                e.printStackTrace();
            }
&#13;
&#13;
&#13;

my error

感谢所有人给予的帮助。

0 个答案:

没有答案