图片流操作:
//conn.getInputStream()获取url所访问图片的InputStream字节流
//formatName是图片的扩展名如:“jpg/gif”等
//Constant.PATH为新图片的地址
//pictureName新图片的名称
String smsUrl = "http://" + resConfig.getCommonShowAddress()+"/" + sms.getSmsUrl();
URL url = null;
URLConnection conn = null;
url = new URL(smsUrl);
conn = url.openConnection();
BufferedImage image = ImageIO.read(conn.getInputStream());
String formatName = filePostfix.substring(1, filePostfix.length());
ImageIO.write(image, formatName, new File(Constant.PATH, pictureName)); 如果不是图片:
jar包是uploadbean.jar
UploadBean 使用的是javazoom.upload.UploadBean
String filename = user.getUserName() + Constant.getDate() + ".lst"; //信息索引文件
String bodyFileName = Constant.getDate() + ".tel"; //电话文件
String messageFileName = Constant.getDate() + ".txt"; //彩信的文本内容。
String pictureName = Constant.getDate() +filePostfix ; //图片名称
UploadBean upload = new UploadBean();
upload.setParser(MultipartFormDataRequest.COSPARSER);
upload.setWhitelist(Constant.WHITELIST);
upload.setFolderstore(Constant.PATH);
telStr = strBuff.toString().trim();
FileOutputStream bodyfos = new FileOutputStream(new File(Constant.PATH, bodyFileName));
BufferedWriter bodytbw = new BufferedWriter(new OutputStreamWriter(bodyfos, "GBK"));
bodytbw.write("\"" + telStr + "\"");
bodytbw.flush();
bodytbw.close();
bodyfos.close();
生成的文件名称有中文。
FileOutputStream fos = new FileOutputStream(new File(Constant.PATH, new String(filename.getBytes("GBK"))));
BufferedWriter stdout = new BufferedWriter(new OutputStreamWriter(fos, "GBK"));
stdout.write(sb.toString());//sb.toString()是写入文件的内容。
stdout.flush();
stdout.close();
fos.close();