diff options
Diffstat (limited to 'main/src/cgeo/geocaching/utils/FileUtils.java')
| -rw-r--r-- | main/src/cgeo/geocaching/utils/FileUtils.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/utils/FileUtils.java b/main/src/cgeo/geocaching/utils/FileUtils.java index f650216..54553c2 100644 --- a/main/src/cgeo/geocaching/utils/FileUtils.java +++ b/main/src/cgeo/geocaching/utils/FileUtils.java @@ -1,12 +1,20 @@ package cgeo.geocaching.utils; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringUtils; import android.os.Handler; import android.os.Message; +import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; import java.util.List; /** @@ -126,4 +134,23 @@ public final class FileUtils { } return success; } + + public static boolean writeFileUTF16(File file, String content) { + // TODO: replace by some apache.commons IOUtils or FileUtils code + Writer fileWriter = null; + BufferedOutputStream buffer = null; + try { + final OutputStream os = new FileOutputStream(file); + buffer = new BufferedOutputStream(os); + fileWriter = new OutputStreamWriter(buffer, CharEncoding.UTF_16); + fileWriter.write(content.toString()); + } catch (final IOException e) { + Log.e("FieldnoteExport.ExportTask export", e); + return false; + } finally { + IOUtils.closeQuietly(fileWriter); + IOUtils.closeQuietly(buffer); + } + return true; + } } |
