InputStream stream = this.getClass().getResourceAsStream("testApp.properties");

解决方案 »

  1.   

    new FileInputStream(".\\filename");
      

  2.   

    new FileInputStream("filename");
      

  3.   

    我的程序为,这里按你们用的方法都试过了不行,new FileInputStream("")应该怎样写啊!
        static{
            try {
                System.getProperties().load(new FileInputStream(""));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        
        public static void main(String[] args) {
            
            System.out.println(System.getProperties().getProperty("var2"));
        }
      

  4.   

    改了一下,这样可以了
    public class ReadProperties {
        
        static{
            try {
                ReadProperties a = new ReadProperties();
                InputStream stream = a.mm();
                System.getProperties().load(stream);
            } catch (FileNotFoundException e) {
                // TODO 自动生成 catch 块
                e.printStackTrace();
            } catch (IOException e) {
                // TODO 自动生成 catch 块
                e.printStackTrace();
            }
        }
        
        InputStream mm() {
            InputStream stream = this.getClass().getResourceAsStream("constants.properties");
            return stream;
        }
        
        public static void main(String[] args) {
            System.out.println(System.getProperties().getProperty("var2"));
        }
    }