3

I am currently creating a directory based on file names and then moving the files into the new directories. At the moment i am creating the new directories fine using the following code:

String filename = filesInFolder.get(i).toString();
File fullPathFile = new File(filename.replaceAll("(\\w+)_(\\d+).*", "$1/$2/$0"));
fullPathFile.getParentFile().mkdirs();

Then i am trying to use InputStream and OutputStream to move the files to the new directories, the code is ok it seems but when i create the new directories, all the folders are set to read-only so i cannot move the files into the knew directories

So is there a way to set the folders to read-write when they are created?

Hip Hip Array
  • 4,665
  • 11
  • 49
  • 80

1 Answers1

3

I believe fullPathFile.getParentFile().setWritable(true) before calling mkdirs() should do. The method setWritable (bool) is a convenience method to set the owner's write permission for this abstract pathname.
Since is a File, you can apply it.

Joseph Elcid
  • 887
  • 1
  • 6
  • 21
  • when I try to do this i get an error 'boolean cannot be dereferenced', it will let me add setWritable(true) after getParentFile() but it will not leave me add .mkdirs() after so, any ideas? – Hip Hip Array May 25 '12 at 10:23
  • I'll look at the problem, but I tried it and it works. You should the API for more details. Do you mean that the method mkdirs() is no longer available? If I getting what you're saying, you are writing `fullPathFile.getParentFile().setWritable(true).mkdirs`? If yes, then its normal, because setWritable (bool) will return a boolean which tells whether the permission change failed or succeded. – Joseph Elcid May 25 '12 at 11:51