gpt4 book ai didi

java - 无法使用 for 创建 .txt

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

我想在 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

最佳答案

您正在尝试重新分配给变量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();
}

关于java - 无法使用 for 创建 .txt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22283941/

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