gpt4 book ai didi

java - StandardOpenOption 问题 java

转载 作者:行者123 更新时间:2023-11-29 08:31:06 25 4
gpt4 key购买 nike

<分区>

我有这个简单的 java 代码:

import java.nio.file.*;
import java.io.*;

public class Write {
public static final String PATH = "/home/user/Desktop/hello.txt";

public static void main(String[] argv) {
Path path = Paths.get(PATH);
OutputStream out;
try {
out = Files.newOutputStream(path, CREATE, APPEND);
} catch (IOException e) {
System.out.println("Caught IOException: "+e.getMessage());
}

}
}

由于这个错误而无法编译:

Write.java:14: error: cannot find symbol
out = Files.newOutputStream(path, CREATE, APPEND);
^
symbol: variable CREATE
location: class Write
Write.java:14: error: cannot find symbol
out = Files.newOutputStream(path, CREATE, APPEND);
^
symbol: variable APPEND
location: class Write
2 errors

通常这意味着我忘记导入一些东西。我什至尝试添加:

import java.nio.file.StandardOpenOption 

但我得到了同样的错误。

编辑: 好的,我已经按照@rmlan 的建议解决了我的问题。我确实错过了那些常量。谢谢。

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