How can I make OS X recognize drive letters?

后端 未结 7 1601
长情又很酷
长情又很酷 2021-01-20 23:11

I know. Heresy. But I\'m in a bind. I have a lot of config files that use absolute path names, which creates an incompatibility between OS X and Windows. If I can get OS X (

7条回答
  •  猫巷女王i
    2021-01-20 23:46

    Here's what I finally ended up doing:

    I downloaded the source code for the java.io package, and tweaked the code for java.io.File to look for path names that start with a letter and a colon. If it finds one, it prepends "/Volumes/" to the path name, coughs a warning into System.err, then continues as normal.

    I've added symlinks under /Volumes to the "drives" I need mapped, so I have:

    • /Volumes/S:
    • /Volumes/Q:

    I put it into its own jar, and put that jar at the front of the classpath for this project only. This way, the hack affects only me, and only this project.

    Net result: java.io.File sees a path like "S:/bling.properties", and then checks the OS. If the OS is OS X, it prepends "/Volumes/", and looks for a file in /Volumes/S:/bling.properties, which is fine, because it can just follow the symlink.

    Yeah, it's ugly as hell. But it gets the job done for today.

提交回复
热议问题