• Post Reply Bookmark Topic Watch Topic
  • New Topic

File Permissions  RSS feed

 
Meadowlark Bradsher
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an object that will create a directory for me, and can also make a file. But it won't do both, it won't make a file in the directory. I found out that every directory it creates has restricted write access and I believe that this is the reason. I can't find any methods in File for changing the permission to be writeable, only to restrict the access. Under this restraint I would have to manually change the permission which if I have to do defeats the purpose of having the object do it.
Is there a solution that I am not aware of? Or is this a security measure to prevent hackers from arbitrarily changing file permissions to be more loose?
Has anybody pondered this question before myself?

Meadowlark Bradsher
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
Meadowlark Bradsher
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I can't find an answer either.
I think it may be something in the way the server's virtual directory system works. Since I am using www.mycgiserver.com a free application server service, I don't feel I am entitled to have this default permission level changed. Its worth a try to ask but perhaps I shouldn't expect to make a directory for every user. Perhaps I'll have a virtual xml directory file that assigns a filename prefix (first 4 characters of the filename or something) to a user. The remaining characters in the filename are to indicate the date the message was received.
However if the files I create are read-only as well I had better create the contents before I create the file.

Meadowlark Bradsher
 
Ryan Langley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,


It is possible to create a directory, and then a file in that directory. I'm not familiar with the intricaces of your environment, but I would think that in the object can create a directory in it then is should have all the permissions necessary to create a file in that directory. Here is some code that I wrote that does this task in the Win2K environment. Good luck!


RL





import java.io.*;
public class FileStructure {
public static void main(String[] args) throws IOException {
File myDir = new File("myDir");
myDir.mkdir();
if(myDir.isDirectory()) {
File myFile = new File(myDir, "myFile.txt");

FileOutputStream fos = new FileOutputStream(myFile);
PrintStream ps = new PrintStream(fos);

ps.println("fubar");

ps.close();
fos.close();
}

System.out.println("\nListing of created directory: ");
String[] dirList = myDir.list();
for(int i = 0; i < dirList.length; ++i)
System.out.println(myDir.getAbsolutePath()
+ File.separator
+ dirList[i]);
}
}



 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!