从jar 包中读取文件,并且复制到jar包的目录中

	public static File createKillspinnersFile() {
		String path = SeleniumUtil.class.getProtectionDomain().getCodeSource()
				.getLocation().getPath();
		File file = new File(path);
		File killspinners = null;
		if (file.exists()) {
			killspinners = new File(file.isDirectory()?file:file.getParentFile(),
					"killspinners-1.1.1-fx.xpi");
			if(killspinners.isFile() && killspinners.exists()){
				return killspinners;
			}
		}else{
			log.error("localtion path is not exists");
		}
		URL plugin = SeleniumUtil.class
				.getResource("/plugin/killspinners-1.1.1-fx.xpi");
		InputStream in = null;
		try {
			in = plugin.openStream();
			FileUtils.writeByteArrayToFile(killspinners, IOUtils.toByteArray(in));
			log.error("createKillspinnersFile succeed");
		}catch (Exception e) {
			log.error(e.getMessage(), e);
		}finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
					log.error(e.getMessage(), e);
				}
			}
		}
		return killspinners;

	}
	

 

你可能感兴趣的:(jar包)