开发者

Saving a string Android

开发者 https://www.devze.com 2023-02-19 03:12 出处:网络
I\'m trying to save a url as a string so that I can use it in another part of my app but its not working properly. Here\'s what I have.

I'm trying to save a url as a string so that I can use it in another part of my app but its not working properly. Here's what I have.

Saving

        String FILENAME = "usertimetable";
        String string = mWebView.getOriginalUrl();

        FileOutputStream fos = null;
        try {
            fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
            fos.write(string.getBytes());
            fos.close();
        } catch (FileNotFoundExceptio开发者_运维问答n e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

Opening

        FileInputStream fis = null;
    try {
        fis = openFileInput("usertimetable");
        url = fis.toString();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


Try using the read() method, rather than toString().

(http://developer.android.com/reference/java/io/FileInputStream.html for more info.)

0

精彩评论

暂无评论...
验证码 换一张
取 消