안드로이드 개발 질문/답변
(글 수 45,052)
제가 텍스트를 저장하려고 하는데요.. 디렉터리까지는 잘 만들어지는데 txt파일이 생성이 안되네요ㅠ
sd카드 권한은 모두 들어가있는 상태입니다.
코드는 이렇습니다.ㅠ 해결방법을 알려주시옵서서.
String dirPath = getFilesDir().getAbsolutePath();
File file = new File(dirPath);
// 일치하는 폴더가 없으면 생성
if( !file.exists() ) {
file.mkdirs();
Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
}
// txt 파일 생성
String testStr = "ABCDEFGHIJK...";
File savefile = new File(dirPath+"/test.txt");
try{
FileOutputStream fos = new FileOutputStream(savefile);
fos.write(testStr.getBytes());
fos.close();
Toast.makeText(this, "Save Success", Toast.LENGTH_SHORT).show();
} catch(IOException e){}




fos.flush() 넣어보세요