将文件添加到我的类路径中
问题描述:
import java.io.*;
import java.util.Properties;
public class Input
{
// This code is nasty and not exception safe. Just demo code!
public static void main(String[] args) throws Exception
{
InputStream stream = Input.class.getResourceAsStream("SomeTextFile.txt");
InputStreamReader is=new InputStreamReader(stream);
BufferedReader br =new BufferedReader(is);
String str=null;
while ((str = br.readLine()) != null) {
System.out.println(str);
}
}
}
这是我的班级,我的文件名是 SomeTextFile.txt位于C:\ MyProgram中,而Input.class文件位于D:\ myjava中,我想在commandprompt中运行这个程序,比如 D:\ myjava> javac Input.java
- 然后它将编译
D:\ myjava> java输入 - 然后它会显示错误
我也给java -classpath C:\ MyProgram输入并运行也一样错误。
我是java的新手,请有人帮我提供我在commandprompt中提供的内容吗?
Hi,this is my class and my file name is "SomeTextFile.txt" which is located in C:\MyProgram,and the Input.class file is located in D:\myjava ,I want to run this program in commandprompt,likeD:\myjava>javac Input.java
-then it will compileD:\myjava>java Input
-then it will showing error
also i give java -classpath C:\MyProgram Input and run also same error.
I am new in java ,please someone help me what i have to give in commandprompt?
答
请使用体面的IDE像Eclipse或Netbeans。两者都是免费的,都可以正常工作,两者都可以为你编译。
Please use a decent IDE like Eclipse or Netbeans. Both are free, both work fine and both will do the compiling for you.