Skip to content

Instantly share code, notes, and snippets.

@daichan4649
Created December 27, 2013 00:59
Show Gist options
  • Save daichan4649/8140977 to your computer and use it in GitHub Desktop.
Save daichan4649/8140977 to your computer and use it in GitHub Desktop.
テキスト内容をファイル出力 (Android)
public class DebugUtil {
private static final String DIRPATH_DEFAULT = "/mnt/sdcard/debug";
private static final String FILENAME_DEFAULT = "tmp.txt";
public static void flushText(String text) {
String path = String.format("%s/%s", DIRPATH_DEFAULT, FILENAME_DEFAULT);
flushText(text, path);
}
public static void flushText(String text, String filePath) {
File file = new File(filePath);
FileOutputStream fos = null;
OutputStreamWriter osw = null;
try {
fos = new FileOutputStream(file);
osw = new OutputStreamWriter(fos);
osw.write(text);
} catch (FileNotFoundException e) {
} catch (IOException e) {
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment