4

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 less lines of code?

yegor256
  • 97,508
  • 114
  • 426
  • 573

1 Answers1

11

If you have apache IOUtils

    URL url = new URL("jar:file:/path/my.jar!/META-INF/file.txt");
    String myString = IOUtils.toString(url);
neu242
  • 15,777
  • 17
  • 75
  • 111
Bala R
  • 104,615
  • 23
  • 192
  • 207