inputstream 转 string 转 outputstream

来源:互联网 发布:武汉淘宝摄影工作室 编辑:程序博客网 时间:2024/06/03 15:07
public static void main(String[] args) throws IOException {
        File f = new File("E:"+File.separator+"1.doc");  
        InputStream in = new FileInputStream(f);  
        ByteArrayOutputStream baos = new ByteArrayOutputStream();  
        int i;  
        while ((i = in.read()) != -1) {  
            baos.write(i);  
        }  
        String str = baos.toString("ISO-8859-1");
        str = java.net.URLEncoder.encode(str, "UTF-8");
        System.out.println(str);    
        
        
        File fo = new File("E:"+File.separator+"2.doc");
        OutputStream os = new FileOutputStream(fo);  
        str = java.net.URLDecoder.decode(str, "UTF-8");
        os.write(str.getBytes("ISO-8859-1"));
        os.close();
    }
0 0
原创粉丝点击