JAVA读取properties
InputStream is=null; OutputStream os=null; Properties props = new Properties(); InputStream in = null; //读取properties try { //第一种,通过类加载器进行获取properties文件流 //in = PropertyUtil.class.getClassLoader().getResourceAsStream("sysConfig.properties"); //第二种,通过类进行获取properties文件流 in = CardUtil.class.getResourceAsStream("/card.properties"); props.load(in); props.getProperty("key"); } catch (FileNotFoundException e) { //logger.error("sysConfig.properties文件未找到"); e.printStackTrace(); } catch (IOException e) { //logger.error("出现IOException"); e.printStackTrace(); } finally { try { if(null != in) { in.close(); } } catch (IOException e) { //logger.error("sysConfig.properties文件流关闭出现异常"); e.printStackTrace(); } } String urlAll=null; String NewmyFileFileName=null; try { is = new BufferedInputStream(new FileInputStream(myFile)); String uuid = UUID.randomUUID().toString().replaceAll("-", ""); NewmyFileFileName=uuid+myFileFileName.substring(myFileFileName.lastIndexOf(".")); urlAll=props.getProperty("toPath")+NewmyFileFileName; os = new BufferedOutputStream(new FileOutputStream(urlAll)); byte[] buffer = new byte[1024]; int len=0; while((len=is.read(buffer))>0){ os.write(buffer,0,len); } }finally{ if(is !=null){is.close();} if(os!=null){os.close();} }