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

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 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
在将字符串保存到流之前对其进行加密,并以其他方式读取它。如果您希望文件内容不可读,加密将是一个胜利。
Encrypt the String before saving it to the stream and the other way to read it. If you want your file's contents to be unreadable, encryption would be a win.