开发者

Adobe AIR - Write a file and specify as read-only

Can we write files to the file system and leave them as read-only in Adobe AIR?

In the future, we would overwrite these files (or delete them and write a new one).


Update:

I tried the following approach, but I was still able to open the file, edit, and save to the file system after the process executed.

var testFile:File = File.desktopDirectory;
var testFileStream:FileStream = new FileStream();
testFile = testFile.resolvePath("testreadonly.txt");
testFileStream.open(testFile, FileMod开发者_开发技巧e.WRITE);
testFileStream.writeUTF("test read only string");
testFileStream.close();     

var readFileStream:FileStream = new FileStream();
readFileStream.open(testFile, FileMode.READ);  
var test:String = readFileStream.readUTF()      

Alert.show("DONE, READ" + test);  


You do not have API in Adobe AIR in order to modify file attributes (like read only, hidden etc). The mode property specifies how do you want to open the file in your session, it does not set any read only flag.


You can. You are probably using a FileStream to write to a file, so when you open it you can specify the mode you want to open the file with. My approach would be to write to the file, close the FileStream and reopen it readonly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜