Java 读取jar内的文件

 
 
private static String jarPath = Encrypt.class.getProtectionDomain().getCodeSource().getLocation().getFile();
URL url=new URL("jar:file:" + jarPath + "!/a.txt");
InputStream fis = url.openStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int read = -1;
while ((read = fis.read(buf)) > 0) {
    bos.write(buf,0,read);
}
String base64Str = new String(bos.toByteArray());

猜你喜欢

转载自blog.csdn.net/java_exception_souji/article/details/78362215
今日推荐