在java中如何将数据从URL中的文件复制到excel工作表中

时间:2015-03-02 05:54:22

标签: java networking urlconnection

我正在使用系统,需要使用java URLConnection从URL获取文件,现在我需要将该内容复制到excel文件中。         这是我的代码。

class getsize {

    public static void main(String args[]) throws Exception {
        HttpURLConnection conn = null;
        try {

            String plainCreds = "hmhinstall:hmh201208";
            //          String url = "http://content.link-systems.com/~hbern/content_update/";
            byte[] plainCredsBytes = plainCreds.getBytes();
            String base64CredsBytes = Base64.encode(plainCredsBytes);
            String base64Creds = base64CredsBytes;
            System.out.println(base64Creds);
            int code = 0;

            URL url = new URL("http://content.link-systems.com/~hbern/content_update/ ");
//Reading
            URLConnection uc = url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    uc.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                System.out.println(inputLine);    //Printing file data
}
            in.close();

//Getting size

            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Authorization", "Basic " + base64Creds);
            conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
            conn.setDoOutput(true);
            System.out.println(conn.getResponseCode());
            System.out.println(conn.getContentType());

            conn.getInputStream();
            System.out.println("Length : " + conn.getContentLength()); //Getting content length

        } catch (Exception exception) {
        } finally {
            conn.disconnect(); //Disconnect
        }

    }
}

如何将文件内容复制到Excel工作表?这样我就可以自动生成记录了。 提前谢谢

0 个答案:

没有答案