在java中从txt读取变量
这是我的密码:在java中从txt读取变量,java,xml,jdom,jdom-2,Java,Xml,Jdom,Jdom 2,这是我的密码: try{ if(fichadaHecha==false) { Element fichada = new Element("fichada"); //Nº TERMINAL fichada.addContent(new Element("N_Terminal").setText("XX")); //TARJETA
try{
if(fichadaHecha==false)
{
Element fichada = new Element("fichada");
//Nº TERMINAL
fichada.addContent(new Element("N_Terminal").setText("XX"));
//TARJETA
fichada.addContent(new Element("Tarjeta").setText(codOperario));
//FECHA
Date fechaFormatoFecha = new Date( );
fichada.addContent(new Element("Fecha").setText(formatoFecha.format(fechaFormatoFecha)));
//HORA
Date fechaFormatoHora = new Date( );
fichada.addContent(new Element("Hora").setText(formatoHora.format(fechaFormatoHora)));
//CAUSA
fichada.addContent(new Element("Causa").setText("0"));
doc.getRootElement().addContent(fichada);
XMLOutputter xmlOutput = new XMLOutputter();
xmlOutput.setFormat(Format.getPrettyFormat());
xmlOutput.output(doc, new FileWriter("C:\\fichadas.xml"));
contador=contador+1;
//fichadaHecha=true;
}
} catch(IOException io){
}
}
}, 0L, 5000);
这是我的conf.txt
N_TERMINAL=18
我想使用conf.txt上的N_TERMINAL(18)的值在这里使用它
fichada.addContent(新元素(“N_终端”).setText(“此处”)代码>
有人知道怎么做吗?谢谢,但eclipse告诉我filereader无法解析为类型,我需要导入?@marcssCtrl+Maj+O
将在eclipse上解析导入;)噢,谢谢,现在eclipse向我展示了:这行有多个标记-未处理的异常类型IOException-未处理的异常类型FileNotFoundException@marcss您需要一个try/catch
块,Ctrl+Shift+1
打开eclipse提供的快速解析工具,它可以
Properties props = new Properties();
props.load(new FileReader("conf.txt"));
fichada.addContent(new Element("N_Terminal").setText(props.getProperty("N_TERMINAL")));