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());
Java 读取jar内的文件
最新推荐文章于 2024-07-23 21:37:41 发布
本文介绍了一个使用Java从JAR包内部读取文件并将其转换为Base64编码字符串的方法。通过示例代码展示了如何打开输入流、读取文件内容,并将读取的数据写入到字节数组中进行Base64编码。
687

被折叠的 条评论
为什么被折叠?



