将文件添加到我的类路径中 [英] add a file into my classpath

查看:157
本文介绍了将文件添加到我的类路径中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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,like

D:\myjava>javac Input.java -then it will compile

D:\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.


这篇关于将文件添加到我的类路径中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆