在Android中的Files中以二进制格式写入数据

发布于 11-07 22:05 字数 837 浏览 3 评论 0原文

大家好: 制作一个示例应用程序,我们可以在其中将数据存储在文件上,然后可以读取它。 我使用以下代码:
要写入的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扭转时空2024-11-14 22:05:27

您可以使用 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:

You can save files directly on the device's internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed.

Here you can find the docs: http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

寄意2024-11-14 22:05:27

在将字符串保存到流之前对其进行加密,并以其他方式读取它。如果您希望文件内容不可读,加密将是一个胜利。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文