我们如何复制文件,并保留其在Android的只读属性? [英] How do we copy files and retain their read only attribute in Android?

查看:694
本文介绍了我们如何复制文件,并保留其在Android的只读属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序,我希望能够复制只读文件,并有新的版本也只读取。

In my Android app, I would like to be able to copy a read only file and have the new version also read only.

在目标文件使用通过setReadOnly()方法只返回假,这表明它失败,当然检查文件本身表明,它一直没有只读属性集。

Using the setReadOnly() method on the destination file only returns false, showing that it failed, and of course checking the file itself shows that it has not had the read only attribute set.

- edit--正如David下面给出的建议,这仅适用于SD卡上的文件。内部文件将适当地表现与通过setReadOnly()。

--edit-- As David Given suggests below, this only applies to files on the SD card. Internal files will behave appropriately with setReadOnly().

我的清单文件具有行<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/> 和我能够做各种在我的应用程序成功的其他文件操作。

My manifest file has the line<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> and I'm able to do all sorts of other file operations successfully in my app.

在寻找一个解决方案,我见过一对夫妇使用Linux命令的人,他们说,这是做一个'肮脏'的方式,所以是有另一种干净提供给我们的方式?

In looking for a solution I've seen a couple of people using linux commands, and they've said that this is a 'dirty' way of doing it, so is there an alternative 'clean' way available to us?

我写的采用了Android 2.1,如果这是相关的。这个应用程序

The app I'm writing is using Android 2.1 if that's relevant.

推荐答案

我不相信的SD卡支持文件属性这样。我想你只能使文件只读的内部存储。 (由于SD卡使用FAT文件系统,但内部存储器使用适当的Linux文件系统)。

I don't believe the SD card supports file attributes like this. I think you can only make files read-only on the internal storage. (Because the SD card uses a FAT file system, but the internal storage uses a proper Linux filesystem.)

检查通过setReadOnly的结果(),看它是否是返回真正

Check the result of setReadOnly() and see whether it's returning true or false.

这篇关于我们如何复制文件,并保留其在Android的只读属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆