0
我在我的個人電腦和Android上的客戶端上製作服務器...我通過套接字和客戶端android編寫jpg文件,併成功讀取並顯示。但我想保存到SD卡。請幫忙...Android - 如何將文件從服務器套接字保存到sdcard pdf和jpg ...?
我在我的個人電腦和Android上的客戶端上製作服務器...我通過套接字和客戶端android編寫jpg文件,併成功讀取並顯示。但我想保存到SD卡。請幫忙...Android - 如何將文件從服務器套接字保存到sdcard pdf和jpg ...?
private void copytoSD() throws IOException{
//Open your local file as the input stream
InputStream myInput = //your input Stream
// Path to the just created empty db
String outFileName = Environment.getExternalStorageDirectory().toString+"/filename.jpg";
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[2048];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}