gpt4 book ai didi

java - "Method in Class cannot be applied to given types"的问题

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

我正在开发一个数字时间胶囊,并将其作为一个有趣的小项目托管在我的 Raspberry Pi 上。我的程序设置为像常规命令提示符一样工作,当您输入特定命令时,它会下载新闻网站的副本并将其存储到 Apache 文件夹(需要设置!)以便从网络访问。现在我正在研究一种自主模式,它每 24 小时创建新的文件并创建新文件而不替换旧文件。但问题是在第 434 行它抛出了这个问题。

Method createNewFile in class File cannot be applied to given types;
file.createNewFile(fileName + (count));

非常感谢我得到的任何帮助,这里是问题发生的摘录

class ScheduledLoop extends TimerTask {
URL url;
int count = 0;
public void run() {
System.out.println("Hello World!");
try {
// get URL content
url = new URL("http://www.wsj.com/");
URLConnection conn = url.openConnection();

// open the stream and put it into BufferedReader
BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream()));

String inputLine;

//save to this filename
String fileName = "H:/Retrieval_WSJ.html";
File file = new File(fileName);

if (!file.exists()) {
file.createNewFile();
}
else
{
count++;
file.createNewFile(fileName + (count));
}

//use FileWriter to write file
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);

while ((inputLine = br.readLine()) != null) {
bw.write(inputLine);
}

bw.close();
br.close();

System.out.println("SCHEDULE_LOOP: Retrieval Of Wall Street Journal Finished!");

} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

最佳答案

createNewFile接受 0 个参数,而不是 1 个。

关于java - "Method in Class cannot be applied to given types"的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35677302/

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