给定以下的Java代码存在错误,通过阅读找出共有几处错误。 import java.io.*; public class TestIO { public static void main(String []args){ String str =”文件写入练习”; FileWriter fw = null; //1 try{ fw = new FileWriter(“c:mytext.txt”); //2 fw.writerToEnd(str); //3 }catch(IOException e){ //4 e.printStackTrace(); }finally{ //此处省略关闭流 } } }
区块链毕设网qklbishe.com为您提供问题的解答
给定以下的Java代码存在错误,通过阅读找出共有几处错误。
import java.io.*;
public class TestIO {
public static void main(String []args){
public class TestIO {
public static void main(String []args){
String str =”文件写入练习”; FileWriter fw = null; //1
try{
fw = new FileWriter(“c:mytext.txt”); //2
fw.writerToEnd(str); //3
fw = new FileWriter(“c:mytext.txt”); //2
fw.writerToEnd(str); //3
}catch(IOException e){ //4
e.printStackTrace(); }finally{
//此处省略关闭流 }
e.printStackTrace(); }finally{
//此处省略关闭流 }
} }
在第 2 行的文件路径字符串 "c:mytext.txt" 中,m 应该被转义成 \,否则会被解释器视为转义字符。 在第 3 行,writerToEnd 方法名应该是 write,而不是 writerToEnd。
编辑于 今天 14:15:28
以上就是关于问题给定以下的Java代码存在错误,通过阅读找出共有几处错误。 import java.io.*;
public class TestIO {
public static void main(String []args){ String str =”文件写入练习”; FileWriter fw = null; //1 try{
fw = new FileWriter(“c:mytext.txt”); //2
fw.writerToEnd(str); //3 }catch(IOException e){ //4
e.printStackTrace(); }finally{
//此处省略关闭流 } } }的答案
欢迎关注区块链毕设网-
专业区块链毕业设计成品源码,定制。
区块链NFT链游项目方科学家脚本开发培训