2015-04-23 57 views
0

这里是我的代码:阅读TXT变量在Java中

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 

我想用N_TERMINAL(18)在conf下的值。 TXT用在这里

fichada.addContent(new Element("N_Terminal").setText("HERE"));

是否有人知道如何做到这一点?

回答

2
Properties props = new Properties(); 
props.load(new FileReader("conf.txt")); 
fichada.addContent(new Element("N_Terminal").setText(props.getProperty("N_TERMINAL"))); 
+0

谢谢,但日食表明我的FileReader不能被解析为一个类型的,我需要的imports¿ – marcss

+1

@marcss'按Ctrl +少校+ O'将解决基于Eclipse的进口;) – NiziL

+0

OOOOH,谢谢,现在日食让我发现:多个标记在该行 \t - 未处理的异常类型为IOException \t - 未处理的异常类型 \t FileNotFoundException异常 – marcss