1.涉及的类和方法:URL,HttpURLConnection,openConnection()
2.取得SD卡的访问权限:修改AndroidManifest:
加上 <uses-permission android:name="android.permission.INTERNET"></uses-permission> (internet访问)
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></use-permission>
3.得到存储设备的目录:/SDCARD(一般情况下):
private String SDPATH;
SDPATH = Environment.getExternalStorageDirectory() + "/";
4.判断SD卡上的文件是否存在:通过File对象的exists()方法
public boolean isFileExists(String fileName) {
File file = new File(SDPATH + fileName);
return file.exists();
}
5.在SD卡上创建目录:通过File的mkdir()方法
public File creatSDDir(String dirName) {
File file = new File(SDPATH + dirName);
file.mkdir();
return file;
}
5.在SD卡上创建文件:通过File的creatNewFile()方法
public File CreatSDFile(String fileName) {
File file = new File(SDPATH + fileName);
file.creatNewFile();
return file;
}