public static Connection getConnection() throws SQLException, IOException {
    
    Properties props = new Properties();
    
    String fileName = "GetDb.properties";
    
    FileInputStream in = new FileInputStream(fileName);
    
    props.load(in);  请问各位大侠,ViewDB.properties这个文件应该放在哪个路径下面呢?我试了放在SRC下面不行,总是提示该文件无法找到,谢谢了。

解决方案 »

  1.   

    String fileName = "GetDb.properties"; 
    到底是ViewDB.properties还是GetDb.properties
      

  2.   

    put your property file into your package
     -com.your.pkg
                 -your.java
                 -xxx.properties
    your.class.getResourceAsStream("xxx.properties");
      

  3.   

    String fileName ="C:/GetDb.properties";//这里可以为绝对路径 
    try 
    {
    props.load(new FileInputStream(fileName ));  
    }
    catch (Exception ce) 
    {
    ce.printStackTrace();
    }
      

  4.   

    照你现在
    public static Connection getConnection() throws SQLException, IOException { 
        
        Properties props = new Properties(); 
        
        String fileName = "GetDb.properties"; 
        
        FileInputStream in = new FileInputStream(fileName); 
        
        props.load(in); 
    这么写的话,文件应该放到class文件同级目录才行吧?要么就像楼上写绝对路径去
      

  5.   

    放在 src 下:InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)
    props.load(is);
      

  6.   

    放在与src同级的目录下就行了,即工程路径下