以HTTP形式获取图片流并写入另一个图片

图片流操作:

                 // 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();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值