вот код, который я использовал для создания пути:
public static File root = android.os.Environment
.getExternalStorageDirectory();
public static String path = root.getAbsolutePath() + "/" + directoryName
+ "/";
public static boolean CreateDirectory() {
boolean ret = false;
path = root.getAbsolutePath() + "/" + directoryName + "/";
File folderExisting = new File(root.getAbsolutePath(), directoryName);
if (folderExisting.exists()) {
ret = true;
} else {
ret = folderExisting.mkdir();
// ret = false;
}
return ret;
}
, а затем для сохранения вещей:
public static boolean SaveToSD(List<String> data, String fileName) {
// File root = android.os.Environment.getExternalStorageDirectory();
boolean ret = false;
CreateDirectory();
File file = new File(path, fileName);
try {
FileOutputStream f = new FileOutputStream(file);
PrintWriter pw = new PrintWriter(f);
for (int idx = 0; idx < data.size(); idx++) {
if (data.get(idx) != null)
pw.println(data.get(idx));
}
pw.flush();
pw.close();
f.close();
ret = true;
} catch (FileNotFoundException e) {
ret = false;
e.printStackTrace();
} catch (IOException e) {
ret = false;
e.printStackTrace();
}
return ret;
}
надеюсь, это поможет вам
идля объекта:
FileOutputStream fos = new FileOutputStream("file");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(mb);
oos.close();