在Android中的Files中以二进制格式写入数据
大家好: 制作一个示例应用程序,我们可以在其中将数据存储在文件上,然后可以读取它。 我使用以下代码:
要写入的代码:
OutputStreamWriter out = null;
try {
out = new OutputStreamWriter(openFileOutput("finear.fin", 0));
out.write(data); //data is String variable
out.close();
Toast.makeText(getApplicationContext(), "Data has been Saved! ", Toast.LENGTH_LONG).show();
}
要读取的代码:
instream = openFileInput("finear.fin");
if(instream!=null)
{
InputStreamReader inputReader = new InputStreamReader(instream);
BufferedReader buffreader = new BufferedReader(inputReader);
String dataRead = buffreader.readLine();
}
现在的问题是:数据以简单的文本形式存储,但我希望没有人可以从该文件中读取我的数据,它应该以某种二进制形式或某种符号类型格式存储数据,这样当在 Windows 中打开文件时,它不应该显示存储在文件中的文本或应该显示一些其他数据。但当数据可以以字符串形式读取时我读了。请帮忙
hi all:
making a sample application in which we can store data on File and then could Read it.,
m using the following code.:
Code to Write:
OutputStreamWriter out = null;
try {
out = new OutputStreamWriter(openFileOutput("finear.fin", 0));
out.write(data); //data is String variable
out.close();
Toast.makeText(getApplicationContext(), "Data has been Saved! ", Toast.LENGTH_LONG).show();
}
Code to Read:
instream = openFileInput("finear.fin");
if(instream!=null)
{
InputStreamReader inputReader = new InputStreamReader(instream);
BufferedReader buffreader = new BufferedReader(inputReader);
String dataRead = buffreader.readLine();
}
Now problem is: The Data is stored in simple Text Form but i want that no one could read my data from that file and it should store the data in some binary form or some symbols type format so that when one opens the file in windows it should not display my text stored in the file or should display some other data.. BUT also that data could be readable in String form when i read. PLease Help
您可以使用 Android 的内部存储,这是您的应用程序私有的:
您可以在这里找到文档:http://developer.android。 com/guide/topics/data/data-storage.html#filesInternal
You can use Android's internal storage, which is private to your application:
Here you can find the docs: http://developer.android.com/guide/topics/data/data-storage.html#filesInternal