java读取jar包里文件内容

来源:互联网 发布:北京熊猫公寓 知乎 编辑:程序博客网 时间:2024/05/18 00:27

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;


public class ReadOutJarFile{     
    
       
    publicstatic void main(String[] args) throws Exception{     
       String jarName="C://test.jar";//Jar包所在的位置  
       StringfileName="com/111.txt";//文件在jar包里的路径     
       JarFile jarFile = newJarFile(jarName);//读入jar文件   
       JarEntry entry =jarFile.getJarEntry(fileName);      
       InputStream input =jarFile.getInputStream(entry);//读入需要的文件  
       readFile(input);     
       jarFile.close();     
       
    
    privatestatic void readFile(InputStream input) throws Exception{   
       InputStreamReader isr = new InputStreamReader(input); 
       BufferedReader reader = newBufferedReader(isr);     
       Stringline;     
       while ((line = reader.readLine()) != null){     
           System.out.println(line);     
           
       reader.close();     
        

原创粉丝点击