Java 读取jar内的文件

来源:互联网 发布:数据库防护产品 编辑:程序博客网 时间:2024/06/06 13:51
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());
原创粉丝点击