读取ANSI的Xml文件,转成UTF-8,发送到BizTalk,不乱码

package liu;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

public class YongYou2 {


public static void main(String[] args) {
int TIME_OUT = 30000;//半分钟超时
int responseCode = 0;
        try
        {
        String url="http://10.9.20.24/FromNC_SKXXHC/BTSHTTPReceive.dll";
            URL postUrl = new URL(url);
            HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
            connection.setConnectTimeout(TIME_OUT);
            connection.setReadTimeout(TIME_OUT);
            connection.setDoOutput(true);
            connection.setRequestMethod("POST");
            connection.setUseCaches(false);
            connection.setInstanceFollowRedirects(true);
            connection.setRequestProperty("Content-Type","text/xml");
            connection.connect();

/*
            //将Document对象写入连接的输出流中
    BufferedOutputStream out = new BufferedOutputStream(connection.getOutputStream());
    File file = new File("F:\\FromNC.txt");
   
            InputStream input = new FileInputStream(file);
            byte[] by =  new byte[1024*1024];
            int i=0;
            while((i=input.read(by))!=-1) {
              out.write(by, 0, i);
            }
*/



   
   
    FileInputStream fis = null;
    BufferedOutputStream out = new BufferedOutputStream(connection.getOutputStream());
            fis = new FileInputStream(new File("f:\\FromNC.txt"));
            byte[] buffer = new byte[fis.available()];
            fis.read(buffer);
            String str = new String(buffer, "GBK");
            out.write(str.getBytes("utf-8"));
           
           
            //out.writeChars(content);

            out.flush();
            out.close();

            responseCode = connection.getResponseCode();
            connection.disconnect();
            System.out.println("HttpStatusCode="+responseCode);
           
           
            if (responseCode == 202 || responseCode==200)
                System.out.println("发送成功");
            else
                System.out.println("发送失败");
    }
        catch (Exception e)
        {
        e.printStackTrace();
    }

}

}

你可能感兴趣的:(.net,xml,F#)