java读取文件并上传
2016-03-17 00:00
387 查看
public void uploadSharefile(String title, String bg, int id) { BufferedReader br = null; InputStream is = null; try { String line = null; br = new BufferedReader(new InputStreamReader(new FileInputStream(DBConnection.class.getClassLoader().getResource("").getPath() + "coupons_share.html"), "UTF-8")); StringBuilder str = new StringBuilder(); while ((line = br.readLine()) != null) { str.append(line); } if (br != null) { br.close(); br = null; } is = new ByteArrayInputStream(str.toString().replace("{title}", title).replace("{bg}", "http://images.lvxinlvshi.com/" + bg).getBytes("UTF-8")); AliyunOSS aliyunOSS = new AliyunOSS(); aliyunOSS.setBUCKET_NAME("staticflile"); aliyunOSS.put(is, is.available(), "coupons_share" + id + ".html"); if (is != null) { is.close(); is = null; } if (is != null) { is.close(); is = null; } } catch (IOException e) { e.printStackTrace(); } finally { } }
相关文章推荐
- Java IO流读取/写入/修改某个字符串(通用)
- java反射机制
- java中的远程debug调试
- 分布式事务 Spring+JTA+Atomikos+Hibernate+JMS
- 安装JDK
- eclipse 查看class 所属jar包
- JAVA正则表达式:Pattern类与Matcher类详解(转)
- java JPA之EntityManager
- Spring MVC与JAX-RS比较与分析
- eclipse 默认UTF-8 -Dfile.encoding=UTF-8
- eclipse导入远程git代码及(push、pull、及maven工程导入)
- eclipse 自动注释格式
- JDK中的URLConnection参数详解(转)
- JAX-RS(java restful实现讲解)(转)
- eclipse 添加jar包几种方式对比
- java volatile详解(转)
- java绝对路径及相对路径总结
- Test(TDD)
- spring+mybatis的公用DAO
- spring mvc框架 类初始化2次 解决过程