当前位置: 首页 > 知识库问答 >
问题:

无法为创建.txt

齐凯康
2023-03-14

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

共有1个答案

花飞尘
2023-03-14

您正在尝试重新分配给变量 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();
}
 类似资料:
  • 我面临着我自己无法解决的问题。我想当有Spring经验的人检查时,解决方案可能是显而易见的。 我有一个非常简单的存储库: 就我而言,对象应该在中创建,然后注入到测试类的中。由于某种原因,它根本没有发生。我将感谢任何可能导致解决这个问题的帮助或暗示。

  • Jmeter版本3.2 我已经将jar文件db2jcc.jar、db2jcc4.jar和db2jcc_license_cisuz.jar复制到了lib目录中。 当我执行jdbc请求得到下面error.Not确定我还错过了什么。 无法创建 PoolableConnectionFactory (DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=

  • 我在我的应用程序和Gson转换器中使用了改型。我想使用数据库时,没有互联网连接。我决定用糖兽。但我得到一个。 java.lang.IllegalArgumentException:无法为类创建转换器

  • 我的代码更长,但我没有复制所有的代码,我看到程序停在这里 对不起我的英语。

  • 当我使用TimeTrigger运行我的azure函数时,我遇到这个错误:Microsoft.Azure.WebJobs.Extensions.Timers.Storage:无法为SchrementMonitor创建BlobContainerClient。 我使用主机生成器: 这是函数: csproj: local.settings.json { "IsEncrypted": false," Val

  • 错误: unsatisfiedDependencyException:创建名为“app controller”的bean时出错:通过字段“service”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.unsatisfieddependencyexception:创建名为“jenkins service”的bean时出错:通过字段“repo”表