阅读Java';使用Java程序创建属性文件
系统找不到此行中指定的文件阅读Java';使用Java程序创建属性文件,java,Java,系统找不到此行中指定的文件 package propertiesreader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; /** * * @author */ public class PropertiesReader { /** * @param args t
package propertiesreader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
/**
*
* @author
*/
public class PropertiesReader
{
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException
{
// TODO code application logic here
//Reading properties file in Java example
Properties props = new Properties();
FileInputStream fis = new FileInputStream("c:/jdbc.properties");
//loading properites from properties file
props.load(fis);
//reading proeprty
String username = props.getProperty("jdbc.username");
String driver = props.getProperty("jdbc.driver");
System.out.println("jdbc.username: " + username);
System.out.println("jdbc.driver: " + driver);
}
}
这意味着什么?我该如何解决这一问题?虽然我在linux中编写了更多代码,但我看到在windows中编写代码的人通常使用“:\”代替“:/”。再次检查文件是否存在,然后尝试“:\”或“:\”
见:
您的情况正好相反“系统无法找到此行中指定的文件。这意味着什么?我该如何解决?”-可能意味着文件不存在于您认为的位置。一般来说,为了便于移植,文件应该存储在相对于程序的某个位置,或者存储在操作系统特定的配置位置(例如windows上的
{user.home}\AppData\{You App}
),或者嵌入到应用程序上下文中,取决于文件是否需要可写或是否需要注意文件不存在或您没有访问权限。
FileInputStream fis = new FileInputStream("c:/jdbc.properties");