java通过CLASSPATH读取包内文件】的更多相关文章

读取包内文件,使用的路径一定是相对的classpath路径,比如a,位于包内,此时可以创建读取a的字节流:InputStream in = ReadFile.class.getResourceAsStream("/com/lavasoft/res/a.txt");有了字节流,就能读取到文件内容了.…
java自带了java.util.zip工具可以实现在不解压zip压缩包的情况下读取包内文件的文件名:(注:只能是ZIP格式的,rar我试了不行)代码如下: public static String readZipFile(String path, String str) throws IOException { ZipEntry zipEntry = null; File file = new File(path); if(file.exists()){ //判断文件是否存在 ZipInput…
import java.io.*; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.jar.JarOutputStream; /** * jarPath: jar包所在路径 * jarFilePath: jar中想要修改文件所在…
最近将代码打包成jar包,关于如何处理读取配置文件的问题特此记录一下. out.properties a.jar -com -a.class -in.properties 如上所示,out.properties是于a.jar包在同一文件目录下: in.properties是在a.jar包内部的. 关于a.class如何读取jar内或jar外的配置文件, 如下所示: FileInputStream inputStream1 = new FileInputStream("out.properties…
/// <summary> /// 根据压缩包路径读取此压缩包内文件个数 /// </summary> /// <param name="strAimPath"></param> /// <returns></returns> private int FileInZipCount(string strAimPath) { ZipEntry zipEntry_ = null; FileStream fsFile_ =…
通过tar命令备份.解压缩文件,也可在不解压缩文件时查看包内的文件信息. 使用如下参数: tar -ztvf file.tar.gz 将列出所有包内的文件列表,包括目录 -z, --gzip, --gunzip, --ungzip filter the archive through gzip -t, --list list the contents of an archive -v, --verbose verbosely list files processed -f, --file=ARC…
在写框架时 经常需要扫描classpath指定包路径下带有某个Annotation的类,自己整理了一下 封装成一个工具类了,供大家参考. 源代码ClassPathResourceScanner.java 如下: package com.bytebeats.jupiter.ioc; import com.bytebeats.jupiter.util.ClassHelper;import org.slf4j.Logger;import org.slf4j.LoggerFactory; import…
properties位于src目录下 project --src -----package -----test.properties Properties p = new Properties(); //从输入流中读取属性列表(键和元素对) p.load(DB.class.getClass().getResourceAsStream("/test.properties"));String testKey = p.getProperty("testKey"); 不能这…
http://blog.csdn.net/giser_whu/article/details/41679515 首先,看下本篇博客要达到的效果图: 下面逐步分析如何加载影像及高程文件. 1.WorldWind Java导入数据包 在src源码文件中找到dataimport包,这个包里面的示例代码演示了如何向WW上加载影像及高程文件.可以看到有import和install两种方式,import是简单的以图层的形式加载到WW上:install是指当文件较大时,将文件以本地缓存的方式加载,这里先以im…
World Wind Java 使用IconLayer图层类表现点和多点数据,使用RenderableLayer图层表现线和面数据,一个图层只能对应一组shape文件.World Wind Java首先使用ShapefileLoader类完成对shape文件的读取和加载,再通过createLayerFromSource方法创建RenderableLayer,最后将创建的Layer加在layers上.源码如下: /** * * 方法名称: AddShapeData : * 方法描述: 添加本地sh…