Problem saving file on Motorola Droid, Android 2.1?

无人久伴 提交于 2019-12-11 07:54:37

问题


Two of my users have reported a problem with my Android application, OftSeen Gestures. Both of them are using a Motorola Droid. The app saves a text file which is just a list of gesture names and phone numbers, both strings. It saves the file to the private data area. I don't know that it is this code that is failing but they report the assigned numbers disappearing after the phone comes out of screen sleep. Since the file is reread in OnCreate each time, I'm assuming the file doesn't exist on return.

As soon as I can get my hands on a Droid I will debug it but in the meantime can you see a reason why this save operation would fail on Droid (no other users have reported this)?

    OutputStreamWriter out = new OutputStreamWriter(AppGlobal.getContext().openFileOutput(MAPPINGS_FILE_NAME, 0));

    for (String key : mMap.keySet()) {
        String number = mMap.get(key).number;
        out.write(String.format("%s,%s\n", key, number == null ? "" : number));
    }
    out.close();

AppGlobal.getContext returns the application context and the MAPPINGS_FILE_NAME resolves to "gesture_mappings.txt".

Like I say, I don't know that this is the problem. It could be something else to do with state management inside the app. If anyone has a Droid, maybe they could download the app from Market and test it for me? Note this is a genuine request for help - not an attempt to increase my downloads.


回答1:


This was diagnosed as being caused by extended character sets causing line-breaks to be misinterpreted and was solved by explicitly writing the file using UTF8. See How to read and write UTF-8 to disk on the Android? 1



来源:https://stackoverflow.com/questions/2700983/problem-saving-file-on-motorola-droid-android-2-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!