Android - How to save file from server socket to sdcard pdf and jpg...?
I made server on my PC and Client on android...I write jpg file through socket and client android read and display successfully. But i want to save that to sdcar开发者_JAVA百科d. Please help...
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();
}
精彩评论