我在我的PC和客户端上安装了服务器...我通过socket和客户端android读取并显示成功显示jpg文件。但我想把它保存到SD卡。请帮忙......
答案 0 :(得分:3)
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();
}