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.
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));
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.