1

I have a .ini file that looks like this:

[Filepath]
Inbound=C:\Users\Bilbo\Desktop\Testing

I want to return that exact string (C:\Users\Bilbo\Desktop\Testing) and I have the following code:

public static String ParseIniInbound (File iniFile) throws 
InvalidFileFormatException, IOException {
    String iniFileName = iniFile.toString();
    Ini ini = new Ini(new File(iniFileName));
    String InboundPath= ini.get("Filepath", "Inbound");
    return InboundPath;
}

However, what is returned is C:UsersBilboDesktopTesting

I tried putting quotes around the filepath in the .ini file to read it as a string but that didn't work. I used double slashes (C:\\Users\\Bilbo\\Desktop\\Testing) which returns (C:\Users\Bilbo\Desktop\Testing) but I want to be able to just copy and paste a filepath and not have to manually put in double slashes. Is there a way to read in a string from an .ini file with ini4j or another way around this? Thanks

Warrior990
  • 59
  • 1
  • 5

2 Answers2

0

Well I couldn't find anything about this, except your post so here is my solution, but if this is the intended way it is really dumb.

ini.put("Default_Values", "dWorkflowStart", "C:\\" + "\\User\\" + "\\kh\\" + "\\Desktop\\" 
            + "\\workstuff\\" + "\\samples\\" + "\\test_in");

This puts out [Default_Values] dWorkflowStart = C:\\Users\\kh\\Desktop\\workstuff\\samples\\test_in

0

Yes, The solution (only in Windows) is to put the path with double slashes. Like in java.util.Properties. When you load properties from file, like that:

Properties p = new Properties();
p.load(new FileInputStream(new File("C:\\path\\to\\file.txt")));

If p.txt contains Windows path, it should have double slashes.

Procrastinator
  • 2,526
  • 30
  • 27
  • 36
Gonzo
  • 13
  • 4