直接上代码咯:
String path="/sdcard/letterschat/";
private void write(String filename,InputStream in){
File file=new File(path);if(!file.exists()){
if(!file.mkdirs()){//若创建文件夹不成功
System.out.println("Unable to create external cache directory");
}
}
File targetfile=new File(path+filename);OutputStream os=null;
try{
os=new FileOutputStream(athfile);
int ch=0;
while((ch=in.read())!=-1){
os.write(ch);
}
os.flush();
}
catch(Exception e){
e.printStackTrace();
}
finally{
try{
os.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}