我正在處理一個數字時間膠囊,我將其作爲一個有趣的小項目託管在我的Raspberry Pi上。我的程序設置爲像常規命令提示符那樣工作,當您輸入特定命令時,它會下載新聞網站的副本並將其存儲到需要從Web訪問的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();
}
}
請張貼從最小的,完整的示例摘錄你的代碼,如果你不想粘貼整個文件。 –