我正在使用我在Raspberry Pi上托管的数字时间胶囊作为一个有趣的小项目。我的程序设置为常规命令提示符,当您键入特定命令时,它会下载新闻网站的副本并将其存储到Apache文件夹(需要设置!)以便从Web访问。现在我正在进行自主模式,每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();
}
}