首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >外部存储到内部存储

外部存储到内部存储
EN

Stack Overflow用户
提问于 2013-02-18 14:40:05
回答 2查看 428关注 0票数 0

我正在制作一个程序,它可以将输入的单词保存到sd卡中的文本文件中。然而,在我的平板电脑中安装sd卡有一些错误,所以我考虑将文本文件保存到内部存储。有人能帮我把这个转到内部存储器吗?任何评论都是非常appreciated.thank你。

,这是我的代码:

代码语言:javascript
复制
public void writeToSDFile() {


    File root = android.os.Environment.getExternalStorageDirectory(); 
    tv.append("\nExternal file system root: "+root);    

    File dir = new File (root.getAbsolutePath());
    dir.mkdirs();
    File file = new File(dir, "wordlist.txt");

    try {   


        FileOutputStream f = new FileOutputStream(file);           

        PrintWriter pw = new PrintWriter(f);
        pw.println(stringword);
        pw.append(stringword);        

        pw.flush();
        pw.close();
        f.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        Log.i(TAG, "******* File not found.");
    } catch (IOException e) {
        e.printStackTrace();
    }   
    tv.append("\n\nFile written to "+file);    


}//end writeToSDFile
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-18 14:47:19

由于外部存储是可移动的,因此不应该假定它始终存在。因此,在执行任何io操作之前,请检查存储状态。

关于您对内部存储的问题,有两种方法: 1.在应用程序存储(app cache)中--参考: Environment.getDataDirectory() 2。在公共数据目录中,参考: Context.getCacheDir()。

希望这能有所帮助。

票数 0
EN

Stack Overflow用户

发布于 2013-02-18 14:43:08

这应该可以帮助您:http://developer.android.com/guide/topics/data/data-storage.html

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14938805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档