This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

File Path in Mac and Windows

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am having a hard time figuring this out. I have two applications running on different machines, one on Mac and another on Windows. They both access / create files from a common file path resource. Now, my Mac machine allows to create folders and file names containing special characters, while Windows does not.
The application where I am having the problem is running on Windows and it needs to read and delete the file created by Mac machine. So, the problem arises when the file path has special characters.

Some observations:
I create a folder named ABC_? which when I view from the Mac machine shows ABC_? as the folder name and when I view it from Windows machine, the folder name appears to be ABC_

I tried to make a FileInputStream object for a file inside the folder:

And trimming the special characters (as I viewed from Windows) had this response:


All I want is to obtain the stream of the image kept at that location from an application running on Windows.
 
Sheriff
Posts: 28346
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All that business about Macs and special characters is completely irrelevant. The message says the O/S can't find that file. It means what it says.
 
Swati Sisodia
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wanted to come up with as much detail as I thought would be necessary.

Well, as I mentioned, when I try accessing the file with ABC_? folder name, I get the following exception:

java.io.FileNotFoundException: \\prod1\cust1\ABC_?\myImage.jpg (The filename, directory name, or volume label syntax is incorrect)

which says the syntax is incorrect. But it happens to be the actual path for the file.
 
Paul Clapham
Sheriff
Posts: 28346
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The detail which would have been useful was this: how is this application running? Does the user who is running it have access to that share? Is it running as a service in Windows?
 
Swati Sisodia
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay.

The application is a simple Java Application, that runs always.
The user I am using, has access to the share. (The app can access a file / folder without any special character).
No, it is not a service. It is a Process.

I am working on fixing a bug where it fails to read only from the files which have incorrect syntax according to Windows.

If you would be kind enough to read the Exception detail I posted twice, it says, "The filename, directory name, or volume label syntax is incorrect" but that is the actual path for my file, just that I created it from Mac.

Makes sense?
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are going to be reading files on multiple platforms, you should only use the subset of characters in filenames that are legal for all platforms.
 
Paul Clapham
Sheriff
Posts: 28346
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I responded on the basis of this error message which you posted:

java.io.FileNotFoundException: \\prod1\cust1\ABC_\myImage.jpg (The system cannot find the path specified)



As you can see there are no special characters there. That's why I said that the issue of special characters was irrelevant.
 
Swati Sisodia
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul: No problem.

Bear: Thanks for reply. Reading the java docs (File class), I also have the opinion that characters which are allowed by the underlying platform can only be used for filenames. Probably that's why File class provides this method:
public boolean canRead()
Tests whether the application can read the file denoted by this abstract pathname.

Also, I tried Samba Jcifs API (jcifs.smb.SmbFile), as it handles the file system generically, Windows or Unix, but it also failed to read from a folder with special characters, strengthening my opinion.

Thanks all for your time.
 
knowledge is the difference between drudgery and strategic action -- tiny ad
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic