How to read a file (URL) in a string, in java?

This is the code:

URL url = new URL("jar:file:/path/my.jar!/META-INF/file.txt"); File file = File.createTempFile("foo", ".txt"); file.deleteOnExit(); FileUtils.copyURLToFile(url, file); String txt = FileUtils.readFileToString(file); 

Can I do the same with smaller lines of code?

+4
source share
1 answer

If you have apache IOUtils

  URL url = new URL("jar:file:/path/my.jar!/META-INF/file.txt"); String myString = IOUtils.toString(url); 
+11
source

Source: https://habr.com/ru/post/1343450/


All Articles