Java: searching for a hack to work with Windows file paths on Linux

Say you have a great legacy of ColdFusion on top of Java on top of a Windows application. Files are accessed both through java.io.File and through CFFILE (which, in turn, also uses java.io.File), but is not centralized in any way to a single file access library. In addition, let's say you have file paths, both hard-coded in code and in the database.

In other words, suppose the file paths themselves cannot change. They can be local or remote Windows file paths:

  • C: \ Temp \ file.txt
  • \\ server \ share \ file.txt

Is there a way to run this application on Linux with minimal code changes? I am looking for creative solutions that do not include touching legacy code .

Some ideas:

  • Launch it on WINE. This really works because WINE will translate local paths and has a samba client for remote paths.
  • Is there a way to override java.io.File to perform file path conversion using custom code? In this case, I would translate the remote paths to the mount point.
+5
source share
2 answers

Is there a way to override java.io.File to perform file path conversion using custom code? In this case, I would translate the remote paths to the mount point

, java.io.File , java.io.File.

JVM, java.endorsed.dirs, java -Xbootclasspath/p:path java launcher (java)

!!!

java.io.File , .

-, :

:

 File file = new File("C:\\Users\\oreyes\\etc.txt");

:

File file = new File( Paths.get( "user.dir.etc" ));

Paths

class Paths {
    private static ResourceBundle rs = ResourceBundle.getBundle("file.paths");
    public static String get( String key ) {
        rs.getString( key );
    }
}

IDE ( )

Linux .

, java.io.File .

+6

java.io.File . ( ) , . , .

java.io.File, , , .

java.io.File file1 = new ClassThatExtendsFile("C:\temp\file.txt");

[edit]: CFFILE .

+2

All Articles