[英]IntelliJ does not recognize built-in java classes/functions
Your code is not within a method, but directly within your class definition:您的代码不在方法中,而是直接在类定义中:
public class RequestHandler { // DOES NOT COMPILE
File file = new File("output.txt");
Files.copy(....);
}
The definition of the file variable actually compiles as it looks like a member definition of the class.文件变量的定义实际上编译,因为它看起来像类的成员定义。 But the
Files.copy()
is not a variable declaration, and so it does not work in this place.但是
Files.copy()
不是变量声明,所以它在这个地方不起作用。
Add a function, and it should work, for example:添加一个函数,它应该可以工作,例如:
public class RequestHandler {
File file = new File("output.txt");
public void copyToOutput(InputStream in) {
Files.copy(in, new FileOutputStream(file));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.