• Post Reply Bookmark Topic Watch Topic
  • New Topic

File toString()  RSS feed

 
Emil Jennings
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so when you have a String s = "abc|123|def|456||" and you do the following:

You end up with the array inputValues [0] = "abc", [1] = "123", [2] = "def", [3] = "456", and [4] will be either null, or out of range, I forget which off the top of my head, but I know it won't be in the array because the javadoc states that "Trailing empty strings are therefore not included in the resulting array."

Now for the question:

Regarding Linux directories, the separator for a File is "/", so if I code

I'm expecting "Java is using directory: /home/inputFiles/" to be displayed on the console, but what is displayed is "Java is using directory: /home/inputFiles". Does Java drop the last separator because there is nothing after it?
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Emil Jennings wrote:Does Java drop the last separator because there is nothing after it?

You probably need to look at the source code to be sure, but according to the Javadoc the toString method calls the getPath method and the getPath method description says
The resulting string uses the default name-separator character to separate the names in the name sequence.

so it sounds like String.split may be being used in there somewhere.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16046
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The name of the directory is "inputFiles" and its parent directory has the name "home". The last slash isn't part of the name of the directory itself - so it's perfectly logical that it doesn't show you the slash when you print the path of the directory.
 
Emil Jennings
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuart, there is no split regarding directory names, I was using the split as an example of how Java will ignore something that doesn't exist after a separator.

Jasper, what you're saying makes sense since looking at that directory in Linux it is listed as /home/inputFiles, the issue is that I'm trying to set up Oracle permissions and when permissions are granted on (again, as an example) /home/inputFiles/* I was expecting that to grant permissions on everything within the inputFiles directory, but instead I was receiving a java.security.AccessControlException: the Permission (java.io.FilePermission /home/inputFiles read) has not been granted to userid. However, permissions granted on /home/inputFiles allows me to read and write files within the inputFiles directory.

What I'm having a hard time grasping is that FilePermission states:
A pathname that ends in "/*" (where "/" is the file separator character, File.separatorChar) indicates all the files and directories contained in that directory. A pathname that ends with "/-" indicates (recursively) all files and subdirectories contained in that directory. A pathname consisting of the special token "<<ALL FILES>>" matches any file.

So I was expecting that permissions on /home/inputFiles/* would give access to files in that directory, and that /home/inputFiles/- would give access to files in that directory and it's subdirectories. To me it almost seems as if the directory naming between File and FilePermissions conflict, read/write permissions granted on /home/inputFiles/* doesn't allow me to read or write files in /home/inputFiles/ (which is what FilePermissions says to do), yet read/write permissions on /home/inputFiles does.

I'm just trying to get a solid understanding of what is happening with the directory name so when I explain the issue to others I give them an accurate reason.

Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!