SPRING :: NOTE

[ANDROID] 파일 생성 및 저장 본문

Development Language/JAVA · ANDROID

[ANDROID] 파일 생성 및 저장

RAYZIE 2016. 5. 27. 15:51
반응형
private void dataSaveLog(String _log, String _fileName) 
{
        /* SD CARD 하위에 LOG 폴더를 생성하기 위해 미리 dirPath에 생성 할 폴더명을 추가 */
        String dirPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/LOG/";
        File file = new File(dirPath);

        // 일치하는 폴더가 없으면 생성
        if (!file.exists())
            file.mkdirs();

        // txt 파일 생성
        File savefile = new File(dirPath + "LOG_" + _fileName + ".txt");
        try {
            BufferedWriter bfw = new BufferedWriter(new FileWriter(dirPath + "LOG_" + _fileName + ".txt", true));
            bfw.write(_log);
            bfw.write("\n");
            bfw.flush();
            bfw.close();
        } catch (IOException e) 
        {
            /* Exception */
        }
}
반응형
Comments