Android:Filesystem
lastmod 2018-08-17created 2016-11-244 edits
Example of saving a file on Android
public void fileSave() {
String path = "/sdcard/Test/"; // 파일이 저장될 경로
String fileName = "android.txt"; // 파일 이름
File file = new File(path + fileName);
String text = "저장될 내용"; // 저장될 내용
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file); // 파일 생성
fos.write((text).getBytes()); // 파일에 내용 저장
fos.close(); // 파일 닫기
} catch (IOException e) {
e.printStackTrace();
}
}
If the file is not saved properly, you need to set the permission in the AndroidManifest.xml file as shown below.
See also
Favorite site
- Creating directories and file I/O on Android
- Finding all kinds of directory information on Android
- Complete guide to getting the paths needed for file I/O on Android 1
- Saving files on Android
- Android file I/O, file sharing, SD card
References
-
Android_file_io.pdf ↩