gpt4 book ai didi

java - 从字符串数组创建输出文件

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

我需要创建 4 个输出文件。

我目前获得一个文件。

String url1 = "www.xxxx.com";
String url2 = "www.xxxx.com";
String url3 = "www.xxxx.com";
String url4 = "www.xxxx.com";
String tableaurl[] = {url1,url2,url3,url4};

for(String url : tableaurl)
{
String encodedString = UrlUtils.encodeAnchor(url);
System.out.format("%s\n", encodedString);
URL myURL = new URL(encodedString);
String userpass = "username" + ":" + "password";
String basicAuth = "Basic " + Base64.encode(userpass.getBytes("UTF-8"));
URLConnection myURLConnection = myURL.openConnection(proxy);
myURLConnection.setRequestProperty("Authorization", basicAuth);
myURLConnection.connect();
InputStream is = myURLConnection.getInputStream();
BufferedReader br = null;
File dir = new File(home + File.separator + "collected" + File.separator +"test");
dir.mkdirs();
File file = new File(dir + File.separator + date.getTime());
FileOutputStream fos = new FileOutputStream(file);
StringBuilder sb = new StringBuilder();

最佳答案

如果您想要 4 个文件,则使用 4 个不同的名称。

int i = 0; // Some number counter
for(String url : tableaurl) {
// other code...

i++;
File file = new File(dir + File.separator + i + "_" + date.getTime());

关于java - 从字符串数组创建输出文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40516055/

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