您的位置:首页 > 编程语言 > Java开发

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 {
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: