【发布时间】:2015-05-09 09:47:05
【问题描述】:
我目前正在开发一个 Web 应用程序,我有一个名为 File.xml 的 XML 文件,其中包含 PostgreSQL 连接参数:登录名、密码、ip_address、pilote、端口、bdd。 .我将此文件添加到 Apache Tomcat 的 bin 文件夹中。我有 class.jav,它使用 XML 文件的参数连接到数据库。
当我运行课程时,我得到else 行的结果(找不到文件)。我怀疑该类不会访问 apache bin 文件夹下的 File.xml。怎么办?
private ParamBDD()
{
SAXBuilder sxb = new SAXBuilder();
try
{
mes_documents mes=new mes_documents();
Fichier fichier = new Fichier();
File file=new File("File.xml");
//File file=new File(this.getClass().getResource("/resources/Fichiers_parametres/parametreconnexion_crypte.xml").getFile());
String str_fichier ="File.xml";
if (file.isFile())
{
org.jdom.Document document = sxb.build(new File(str_fichier));
Element racine = document.getRootElement();
List listParam = racine.getChildren("param");
Iterator i = listParam.iterator();
while (i.hasNext())
{
Element courant = (Element) i.next();
pilote = courant.getChild("pilote").getText().trim();
utilisateur = courant.getChild("login").getText().trim();
password = courant.getChild("password").getText().trim();
adresseIP = courant.getChild("adresseIP").getText().trim();
port = courant.getChild("port").getText().trim();
BDDGenerale = courant.getChild("bdd").getText().trim();
System.out.println("BDD Generale:"+BDDGenerale);
//JOptionPane.showMessageDialog(null, "Fin du fichier","",JOptionPane.INFORMATION_MESSAGE);
}
}
else JOptionPane.showMessageDialog(null, "le fichier contenant les parametres n'existe pas","",JOptionPane.INFORMATION_MESSAGE);
}
【问题讨论】:
-
请将您的问题翻译成英文。
-
嗨,阿斯玛,欢迎来到 StackOverflow。你可以编辑你的帖子并提出你的问题in English吗?
-
我目前正在开发一个 Web 应用程序,我有一个名为 File.xml 的 xml 文件,其中包含与 postgresql 数据库的连接参数。我将此文件添加到 apache 的 bin 文件夹中。我有 class.jav,它使用 xml 文件的参数连接到数据库。当我运行课程时,我得到了 else 行的结果。我怀疑该类不会访问 apache bin 文件夹下的 File.xml。怎么办?
-
刚刚翻译。阿斯玛,检查你的牙套。
-
如果您的
File file = ...行确实是注释掉的行,那么这将是您真正的问题。如果File file = ....行是您当前拥有的= new File("File.xml");行,那么您的问题是因为您当前目录中没有名为File.xml的文件。是哪个file?
标签: java tomcat jakarta-ee