Android 保存字符串

发布于 2024-10-25 19:54:22 字数 903 浏览 3 评论 0原文

我正在尝试将 url 保存为字符串,以便我可以在应用程序的其他部分使用它,但它无法正常工作。这就是我所拥有的。

保存

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

        FileOutputStream fos = null;
        try {
            fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
            fos.write(string.getBytes());
            fos.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

开局

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

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 (FileNotFoundException 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();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘羡 2024-11-01 19:54:22

尝试使用 read() 方法,而不是 toString()

(http://developer.android.com/reference/java/io/FileInputStream. html 了解更多信息。)

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文