views:

440

answers:

2

Hey Stack Overflow community,

Another Adobe AIR question for you: 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).

Thanks, Mauricio


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, FileMode.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);  
A: 

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.

ilikeorangutans
I am trying that, but it is not working here. This is what I am doing:var testFile:File = File.desktopDirectory;var testFileStream:FileStream = new FileStream();testFile = testFile.resolvePath("testreadonly.txt");testFileStream.open(testFile, FileMode.WRITE);testFileStream.writeUTF("test read only string");testFileStream.close(); var readFileStream:FileStream = new FileStream();readFileStream.open(testFile, FileMode.READ);
Mauricio
Maybe you should edit your question and put the code there; you can use real code formatting there, makes it easier to read. Which part of your code is not working?
ilikeorangutans
+1  A: 

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.

Cornel Creanga