解决方法
String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { //SDcard is available File f=new File("/sdcard/test.txt"); if (!f.exists()) { //File does not exists f.createNewFile(); } //take your inputstream and write it to your file OutputStream out=new FileOutputStream(f); byte buf[]=new byte[1024]; int len; while((len=inputStream.read(buf))>0) out.write(buf,len); out.close(); inputStream.close(); System.out.println("\nFile is created..................................."); }
不要忘记将以下权限添加到清单中
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>