在android的内部存储中制作一个txt文件 [英] Make a txt file in internal storage in android
本文介绍了在android的内部存储中制作一个txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 root 上创建一个文件夹并放置 txt 文件并附加数据'
i want to make one folder on root and put txt file and append data '
我的java代码
public void generateNoteOnSD(String sFileName, String sBody){
try
{
String fileName = "error";
String headings = "Hello, world!";
String path = "/data/root/";
File file = new File(path, fileName+".txt");
if (!file.exists()) {
file.mkdirs();
}
File gpxfile = new File(file, sFileName);
FileWriter writer = new FileWriter(gpxfile);
writer.append(sBody);
writer.flush();
writer.close();
// Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
}
catch(IOException e)
{
Log.d("file error", ""+e.getMessage());
}
}
我收到文件未找到异常
请帮助我如何在内部存储的根文件夹上创建文件
Please help me how can create a file on root folder in internal storage
推荐答案
试试这个功能.
public void wrtieFileOnInternalStorage(Context mcoContext,String sFileName, String sBody){
File file = new File(mcoContext.getFilesDir(),"mydir");
if(!file.exists()){
file.mkdir();
}
try{
File gpxfile = new File(file, sFileName);
FileWriter writer = new FileWriter(gpxfile);
writer.append(sBody);
writer.flush();
writer.close();
}catch (Exception e){
}
}
这篇关于在android的内部存储中制作一个txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文