gpt4 book ai didi

java - 从指定的 URL 读取 CSV 文件

转载 作者:行者123 更新时间:2023-12-01 12:00:48 25 4
gpt4 key购买 nike

我正在使用这个java程序从我的程序中的指定URL读取csv文件内容,它的问题是它不获取最后64条记录,即它将所有记录获取到我指定的myHello中.csv 文件,最后 64 除外。请帮助。

package com.aamir;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class TestGetCSV {


public static void main(String[] args) {

try {

URL url12 = new URL("https://wd5-impl-services1.workday.com/ccx/service/customreport2//ISU-YINT061-ProjectsFE/YINT061.05-OpenText?format=csv" );

URLConnection uc = url12.openConnection();

String userpass = "username" + ":" + "password";
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());

uc.setRequestProperty ("Authorization", basicAuth);
/* HttpURLConnection conn = (HttpURLConnection)uc;
conn.setInstanceFollowRedirects( false );
*/

InputStreamReader inStream = new InputStreamReader(uc.getInputStream());
BufferedReader buff= new BufferedReader(inStream);

String content2 = null;

BufferedWriter bf = new BufferedWriter(new FileWriter("D:/myHello.csv"));
while ((content2 = buff.readLine()) != null) {

bf.write(content2);

content2 = buff.readLine();
bf.flush();
}
}
catch (Exception e){
e.printStackTrace();
System.out.print("KHONG TAI DUOC DU LIEU");
}
System.out.println("done");

}


}

最佳答案

您在每个循环中都从 BufferedReader 中“双重”消耗。对于每个循环,您调用 readLine() 两次,但只写入一次(因此您将删除每隔一行)。

关于java - 从指定的 URL 读取 CSV 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27990260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com