大家好,帮我看看这些代码。
在eclipse和myeclipse中都会报错。报错位置代码中有说明。
但是,我在DOS下用javac 和java 编译运行,都没有错,这是为什么呢?
谢谢大家!import java.io.*;
public class PrintStream2 { public static void main(String[] args) {
PrintStream ps = null;
try {
FileOutputStream fos = new FileOutputStream("H:\\log.txt");
ps = new PrintStream(fos); //在eclipse中,这一行有红色下滑线报错
} catch (IOException e) {
e.printStackTrace();
}
if(ps != null){
System.setOut(ps); //在eclipse中,这一行有红色下滑线报错
}
int ln = 0;
for(char c = 0; c <= 60000; c++){
System.out.print(c+ " ");
if(ln++ >=100){ System.out.println(); ln = 0;}
}
}
}
在eclipse和myeclipse中都会报错。报错位置代码中有说明。
但是,我在DOS下用javac 和java 编译运行,都没有错,这是为什么呢?
谢谢大家!import java.io.*;
public class PrintStream2 { public static void main(String[] args) {
PrintStream ps = null;
try {
FileOutputStream fos = new FileOutputStream("H:\\log.txt");
ps = new PrintStream(fos); //在eclipse中,这一行有红色下滑线报错
} catch (IOException e) {
e.printStackTrace();
}
if(ps != null){
System.setOut(ps); //在eclipse中,这一行有红色下滑线报错
}
int ln = 0;
for(char c = 0; c <= 60000; c++){
System.out.print(c+ " ");
if(ln++ >=100){ System.out.println(); ln = 0;}
}
}
}
现在和以前用来编译其它程序都没有问题,只有这个程序在编译时会出错。
arguments (PrintStream)
Window-->java-->Installed JREs看看右边的选项,是不是你的虚拟机的路径我已经看过了,所用jre的确是我装的路径位置。
properties-->Java Compiler查看里面的编译JDK版本这里的显示的jdk版是默认6.0
我的eclipse和meclipse都会有相同的报错但是其它程序都正常。
我运行你的程序了,没有提示错误在myeclipse中
起初害的我重了JDK也没有解决问题。原来,我在这个包中建了一个类,类名为PrintStream。这样正好和java.io.PirntStream同名。
相信大家也会明白原因了吧。谢谢大家的关注。