마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

openFileOutput 함수에서

0 추천
OutputStream os = null;  
                PrintWriter pw = null;  
                
                try {  
                      // 현재 시간을 msec으로 구한다.
                    long now = System.currentTimeMillis();
                    // 현재 시간을 저장 한다.
                    Date date = new Date(now);
                    // 시간 포맷으로 만든다.
                    SimpleDateFormat sdfNow = new SimpleDateFormat("yy-MM-dd-HH-mm-ss");
                    String strNowFilename = sdfNow.format(date);
                    strNowFilename += ".txt";

                   
                    os = openFileOutput("/mnt/sdcard/World/"+strNowFilename, Context.MODE_PRIVATE);  
                                    // Context 에 InputStream 을 반환하는   
                                    // openFileInput 메소드.  
                    pw = new PrintWriter(os, true);  
                                    // true는 auto flush  
                    String content = mString;  
                    pw.write(content + "\n");  
                    
                } catch (IOException ie) {  
                    android.util.Log.e("fWriter()", ie.toString());  
                } finally {  
                                // 잊어서는 안되는 닫기.  
                    try {  
                        if (pw != null) {  
                            pw.close();  
                        }  
                        if (os != null) {  
                            os.close();  
                        }  
                    } catch (IOException ie) {  
                        android.util.Log.e("fWriter()", ie.toString());  
                    }  
                }

위코드에서 openFileOutput 함수에서 막바로 finally 로 넘어갑니다

sdcard 에 World 란폴더 있습니다

catch (IOException ie) 도 발생하지않고 finally 로 넘어가는걸까요?
참참참 (3,100 포인트) 님이 2014년 7월 23일 질문

1개의 답변

0 추천

openFileOutput은 어플마다 할당된 특정 폴더에 저장되구요...

sd카드에 저장학하나 불러오는 기능이아닙니다.

sd카드에 저장하기를 원하시면...

File root = Environment.getExternalStorageDirectory();
File file = new File(root, "filename");
FileOutputStream os = new FileOutputStream(file);

처럼 해보세용.

칠리님 (10,910 포인트) 님이 2014년 7월 23일 답변
ddms 모드로해서 파일을확인하려는데
그럼 그냥
 os = openFileOutput(strNowFilename, Context.MODE_PRIVATE);
처럼...

이전 글 처럼 파일확인이 목적이시면 adb shell 해보세용...
...