在intenal存储和本地目录中的Android文件 [英] Android files in intenal storage and local directory
问题描述
Android为您提供GETDIR(我想这意味着我将不得不myappspace / somedirectory)来创建你的应用空间的目录。但如何,如果你有在openFileOutput /输入路径分隔符调用它给你一个错误,你读取或写入文件在该目录中,当机器人给你一个错误?
Android gives you getDir (I assume this means I would have myappspace/somedirectory) to create a directory in you application space. But how do you read or write to a file in that directory when android gives you an error if you have the path separator in the openFileOutput/Input call it gives you an error?
推荐答案
GETDIR返回一个File对象。要操作目录和文件结构,您继续使用File对象。例如:
getDir returns a File object. To manipulate the directory and file structure, you continue to use File objects. For example
File dir = getDir("myDir", Context.MODE_PRIVATE);
File myFile = new File(dir, "myFile");
在openFileOutput只返回基于一些文字标准,一个FileOutputStream。我们所要做的就是创建对象
the openFileOutput simply returns a FileOutputStream based on some text criteria. All we have to do is create the object
FileOutputStream out = new FileOutputStream(myFile);
从这里,你继续正常。
From here, you continue as normal.
String hello = "hello world";
out.write(hello.getBytes());
out.close();
的FileInputStream将遵循相同的准则。
FileInputStream would follow the same guidelines.
这篇关于在intenal存储和本地目录中的Android文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!