Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cross Platform File Path

 
Justin Nauman
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I am currently tasked with writing a service method that abstracts away some of the details about how a file that is uploaded to our web application is stored. The goal here is to allow us to upgrade to a CMS in the future and not have to change a great deal of code.

I admittedly have very little experience in the File I/O area, but the general idea is that our default implementation will be writing the files to a file system and storing the path to a DB, along with some other metadata that is necessary for the application's use.

The issue I could use some help on is: "what is the best way to store the 'path' to the file if our application needs to be deployed across mutliple operating systems?"

The development boxes for unit testing are on Windows, and the production environments sit on UNIX. The server file system itself will also be a Windows system that can be accessed via Unix or Windows. In Windows it would be using the typical UNC file naming conventions like: \\<SERVER_NAME>, but in Unix we have it set up so that there is a symbolic link to the same server at /<SERVER_NAME>.

I have considered just replacing all of the File.SeperatorChars with a REGEX with a character that is OS agnostic before saving it into the DB's FILE_LOCATION column, but this seems a big ugly. Are there any other methods that you have found to work well that I could investigate?

Thanks in advance for your help,
Justin N.
Chicago, IL
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use / with Windows as well - the API is smart enough to convert it to \. So a UNC path of //server/share/folder/file will work just fine.
 
Justin Nauman
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks much! That seems to have done the trick. I didn't really think about what // in a Unix environment would "mean", but it references the root twice, which is no big deal.

Thanks again!
Justin N.
Chicago, IL
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic