想飞就别怕摔

大爷的并TM骂人

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

posted on 2011-06-16 11:15 生命的绽放 阅读(1358) 评论(0)  编辑  收藏 所属分类: JAVA


只有注册用户登录后才能发表评论。


网站导航:
 
<2011年6月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

导航

统计

常用链接

留言簿(5)

随笔分类(94)

随笔档案(93)

文章分类(5)

文章档案(5)

相册

JAVA之桥

SQL之音

兄弟之窗

常用工具下载

积分与排名

最新评论

阅读排行榜