gpt4 book ai didi

java - 我的程序出现错误

转载 作者:行者123 更新时间:2023-11-30 00:19:42 25 4
gpt4 key购买 nike

我收到此错误:

Information:Using javac 1.8.0 to compile java sources
Information:java: Errors occurred while compiling module 'HelloWorld'
Information:Compilation completed with 2 errors and 0 warnings in 6 sec
Information:2 errors
Information:0 warnings
C:\Users\Raj\IdeaProjects\HelloWorld\src\CopyCharacters.java
Error:(18, 29) java: cannot find symbol
symbol: variable c
location: class CopyCharacters
Error:(21, 30) java: cannot find symbol
symbol: variable c
location: class CopyCharacters

我正在练习这个doc ,现在当我使用 intellij idea IDE 运行我的程序时,它给了我这个错误..

这是我的源代码:

import java.io.*;

public class CopyCharacters {
public static void main(String[] args) throws IOException{

FileReader inputstream=null;
FileWriter outputstream=null;

try{
inputstream=new FileReader("D://raj.txt");
outputstream=new FileWriter("D://raj1.txt");

int c;
while((c=inputstream.read())!=-1){
outputstream.write(c);
}
}finally{
if(inputstream!=c){
inputstream.close();
}
if(outputstream!=c){
outputstream.close();
}
}
}
}

已编辑:

根据@我希望我能想到一个好的答案,它正在工作,但它显示了新的错误:

Exception in thread "main" java.lang.ClassNotFoundException: ArrayDemo
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:259)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)

最佳答案

将你最终阻止更改为

    }finally{
if(inputstream!=null){
inputstream.close();
}
if(outputstream!=null){
outputstream.close();
}
}

为什么要将流与 int 进行比较?

完成此操作后,您会发现您可以保持 c 的声明不变。

关于java - 我的程序出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23334619/

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