到目前为止,我还没有编写任何服务器端代码。有什么办法可以尝试编写一个 android 程序,我可以将文件从手机上传到远程服务器?
其他详细信息:- 我的代码-
private void sendToRemoteServer(){
Socket client;
FileInputStream fileInputStream;
BufferedInputStream bufferedInputStream;
OutputStream outputStream;
try{
client = new Socket("10.0.2.2",444);
byte[] myByteArray = new byte[(int)mFile.length()];
fileInputStream = new FileInputStream(mFile);
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();
}catch(UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
我需要确保的是 android 不会出现内存不足异常。