我想在Eclipse中使用for创建10个txt文件 为什么当我这样做时我得到错误?
for (int i=0; i< 10; i++)
File i = new File("C:\\Users\\User\\Desktop\\FOLDER- OS test\\primer" + i + ".txt");
Multiple markers at this line - Syntax error, insert "AssignmentOperator Expression" to complete Assignment - File cannot be resolved to a variable - Syntax error, insert ";" to complete Statement - i cannot be resolved to a variable - i cannot be resolved to a variable
答案 0 :(得分:3)
您正尝试重新分配已定义为i
的变量int
。只需为文件使用另一个变量名称,如下所示:
for (int i=0; i< 10; i++) {
File foo = new File("C:\\Users\\User\\Desktop\\FOLDER- OS test\\primer" + i + ".txt");
foo.createNewFile();
}