- 전체
- android studio
- Android SDK
- Android NDK
- Android ADK
- Android Etc. Lib.
- Android dalvik VM
- Android 보안
- PhoneGap
- AOSP 개발
- MIT App Inventor 2
- kivy (python)
- ionic framework
- Kotlin (코틀린)
- React Native
Android SDK 단말기 내부에 폴더 및 txt파일 생성하기
2016.05.01 09:01
단말기 내부에 폴더 및 txt파일 생성하기
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) {}
}

[출처] http://berabue.tistory.com/24
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.

