import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Java_moodi1 { public static void main(String[] args) { //*********Found******** Path pfile = __________________; try { //*********Found******** BufferedReader br = __________________; String str = null; //*********Found******** while((__________________!=null){ System.out.println(str); } } catch (IOException e) { e.printStackTrace(); } } }完善这个程序
时间: 2023-08-11 22:08:10 浏览: 195
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Java_moodi1 {
public static void main(String[] args) {
Path pfile = Paths.get("file.txt");
try {
BufferedReader br = Files.newBufferedReader(pfile);
String str = null;
while ((str = br.readLine()) != null) {
System.out.println(str);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
相关问题
import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Java_moodi1 { public static void main(String[] args) { //*********Found******** try { //*********Found******** //*********Found******** } } catch (IOException e) { e.printStackTrace(); } } }完善这个程序
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Java_moodi1 {
public static void main(String[] args) {
try {
Path pfile = Paths.get("file.txt");
byte[] data = Files.readAllBytes(pfile);
String content = new String(data);
System.out.println(content);
} catch (IOException e) {
e.printStackTrace();
}
}
}
上面的代码报错:No signature of method: static java.nio.file.Files.write() is applicable for argument types: (java.lang.String, [B) values: [path\to\output\Data.csv.html, [60, 104, 116, 109, 108, 62, 60, ...]] Possible solutions: write(java.nio.file.Path, [B, [Ljava.nio.file.OpenOption;), wait(), write(java.nio.file.Path, java.lang.Iterable, [Ljava.nio.file.OpenOption;), wait(long), wait(long, int), write(java.nio.file.Path, java.lang.Iterable, java.nio.charset.Charset, [Ljava.nio.file.OpenOption;) at Script1685787280790$_run_closure3.doCall(Script1685787280790.groovy:47)
非常抱歉,我之前的代码中存在问题。在Groovy中,`Files.write()`方法的参数类型与Java略有不同,应该使用以下方式调用:
```groovy
Files.write(Paths.get(outputFilePath), htmlBuilder.toString().getBytes())
```
其中,`Paths.get()`方法用于将字符串路径转换为`Path`对象。
请尝试使用这种方式进行修改,看看能否成功执行。如果还有其他问题,请随时告诉我。
阅读全文