Reading path from ini file, backslash escape character disappearing?

断了今生、忘了曾经 提交于 2019-12-05 09:50:05
grkvlt

Try setting the escape property to false in Ini4j.

You can try:

Config.getGlobal().setEscape(false);

If you read the file and then translate the \ to a / before processing, that would work. So the library you are using has a method Ini#load(InputStream) that takes the INI file contents, call it like this:

byte[] data = Files.readAllBytes(Paths.get("directory", "file.ini");
String contents = new String(data).replaceAll("\\\\", "/");
InputStream stream = new ByteArrayInputStream(contents.getBytes());
ini.load(stream);

The processor must be doing the interpretation of the back-slashes, so this will give it data with forward-slashes instead. Or, you could escape the back-slashes before processing, like this:

String contents = new String(data).replaceAll("\\\\", "\\\\\\\\");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!