我正在尝试打印从属性文件获取的值并将其打印到控制台,但我收到此错误,如---->错误消息:“找不到符号和构造函数FileInputStream(java.lang.String ,java.lang.String)“错误正在抛出 如何解决这个问题?
import java.io.FileInputStream;// Adding the Class to read file
import java.io.IOException; // Adding the Class to avoid Exception while reading the file
import java.io.InputStream;// Adding the Class to read file
import java.util.Properties;// Adding the Class to read Property file
import java.lang.String;
class readPropFile
{
public static void main(String args[])
{
Properties prop = new Properties();
InputStream in = null;
try //reading a file here
{
in = new FileInputStream("Sample.properties","D:/MYJAVAPRGMS/Property); // Setting the file name and path to read
prop.load(in);
System.out.println(prop.getProperty("emp_Id"));// reading the Values using Key
System.out.println(prop.getProperty("first_Name"));// reading the Values using Key
System.out.println(prop.getProperty("last_Name"));// reading the Values using Key
System.out.println(prop.getProperty("org_Name")); // reading the Values using Key
}
catch (IOException io) // catch the Exception
{
io.printStackTrace();
}
finally // Finally block to take the value
{
if (in != null)
{
try {
in.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
}
答案 0 :(得分:1)
import java.io.FileInputStream;// Adding the Class to read file
import java.io.IOException; // Adding the Class to avoid Exception while reading the file
import java.io.InputStream;// Adding the Class to read file
import java.util.Properties;// Adding the Class to read Property file
import java.lang.String;
class one
{
public static void main(String args[])
{
Properties prop = new Properties();
InputStream in = null;
try //reading a file here
{
in = new FileInputStream("D://MYJAVAPRGMS//Property//sample.properties");
prop.load(in);
System.out.println(prop.getProperty("emp_Id"));// reading the Values using Key
System.out.println(prop.getProperty("first_Name"));// reading the Values using Key
System.out.println(prop.getProperty("last_Name"));// reading the Values using Key
System.out.println(prop.getProperty("org_Name")); // reading the Values using Key
}
catch (IOException io) // catch the Exception
{
io.printStackTrace();
}
finally // Finally block to take the value
{
if (in != null)
{
try {
in.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
}