Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How does java.io.File handle edge cases?  RSS feed

 
Ken McDonald
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm thinking, for example, of a filename on a UNIX system that might have a '/' embedded in it because it was transferred from a MS system. There doesn't seem to be a way to create such file names, and there is nothing in the documentation (that I can see) that discusses how such cases are handled. Any comments?

Thanks,
Ken
 
Rob Spoor
Sheriff
Posts: 21044
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Microsoft systems don't allow / in the filename, since / is often used for parameters. For example, "tasklist /?".
 
Ken McDonald
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that's helpful at least. What about other special Unixey characters?

Thanks,
Ken
 
Rob Spoor
Sheriff
Posts: 21044
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, only / is disallowed in a file name (I just tested it). "." and ".." are not allowed as full names because these represent the current folder and the parent folder. As such, if you try to create them, you'll be told they already exist.

Other files, not a problem for as far as I know. That does allow for troublesome situations, when you have files called "-rf". If you then call "rm *" it will treat the "-rf" as a flag all of a sudden, which will remove literally everything in your current folder. Fortunately, that can be remedied by appending "./" - "./-rf" is always a file, never a flag.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been able to create files whose name is an empty string on my iSeries machine with Java, although you can't do that from the command line. (It isn't a Unix variety but the command line is Unixey, if you want to use that term.)
 
Ken McDonald
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I have been able to create files whose name is an empty string on my iSeries machine with Java, although you can't do that from the command line. (It isn't a Unix variety but the command line is Unixey, if you want to use that term.)


What's an iSeries machine? As long as it's not UNIX, I'm not too worried.

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