I am trying to read a file in a line using org.apache.commons.io version 2.4 on Windows 7.
String protocol = url.getProtocol(); if(protocol.equals("file")) { File file = new File(url.getPath()); String str = FileUtils.readFileToString(file); }
but fail:
java.io.FileNotFoundException: File 'C:\workspace\project\resources\test%20folder\test.txt' does not exist
but if I do this:
String protocol = url.getProtocol(); if(protocol.equals("file")) { File file = new File("C:\\workspace\\resources\\test folder\\test.txt"); String str = FileUtils.readFileToString(file); }
I work great. Therefore, when I manually type the path with a space / space, it works, but when I create it from the URL, it is not.
What am I missing?
source share