我正在通过 Java 应用程序将文件从 Android 模拟器传输到 PC 服务器。我的客户端应用程序上的代码是...
File file = new File("/mnt/sdcard/sample.mp4"); //create file instance
client = new Socket("10.0.2.2", 4444);
byte[] mybytearray = new byte[(int) file.length()]; //create a byte array to file
fileInputStream = new FileInputStream(file);
bufferedInputStream = new BufferedInputStream(fileInputStream);
bufferedInputStream.read(mybytearray, 0, mybytearray.length); //read the file
outputStream = client.getOutputStream();
outputStream.write(mybytearray, 0, mybytearray.length); //write file to the output stream byte by byte
outputStream.flush();
bufferedInputStream.close();
outputStream.close();
client.close();
但是,当我在 Android 设备本身上运行它时,该应用程序将无法运行。我想我应该用其他值(即:我的 PC 服务器的 IP 地址)替换“10.0.2.2”。我应该把什么价值放在那里?