开发者

How to read file (addressed by URL) into string, in java?

开发者 https://www.devze.com 2023-02-16 05:16 出处:网络
This is the code: URL url = new URL(\"jar:file:/path/my.jar!/META-INF/file.txt\"); File file = File.createTempFile(\"foo\", \".txt\");

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开发者_StackOverflow中文版 I do the same with less lines of code?


If you have apache IOUtils

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

精彩评论

暂无评论...
验证码 换一张
取 消