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){}
// 파일이 1개 이상이면 파일 이름 출력
if ( file.listFiles().length > 0 )
for ( File f : file.listFiles() ) {
String str = f.getName();
Log.v(null,"fileName : "+str);
// 파일 내용 읽어오기
String loadPath = dirPath+"/"+str;
try {
FileInputStream fis = new FileInputStream(loadPath);
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(fis));
String content="", temp="";
while( (temp = bufferReader.readLine()) != null ) {
content += temp;
}
Log.v(null,""+content);
} catch (Exception e) {}
}LogCat 결과
'Android > File' 카테고리의 다른 글
| ZipEntry를 활용한 압축해제 (0) | 2013.06.02 |
|---|---|
| 프로젝트에 포함된 이미지를 SdCard로 이동시키기. (0) | 2011.06.12 |
| Sd Card 이미지 읽어오기 (0) | 2011.02.14 |
| txt 파일 읽어오기 (0) | 2011.02.11 |
| SD Card에 txt 파일로 저장하기 (0) | 2011.02.05 |