قسم الرياضيات و الإعلام الإلي

www.univ-soukahras.dz/ar/dept/mi

المقياس: Bases de données avancées

  1. معلومات
  2. الأسئلة
  3. التعليم عن بعد

How can we put the result that appear at console in a file

2 votes

this is y code 

try {

File file = new File("/C:/Users/workspacememoire12/aaaaa/src/aaaaa/class.xml");
//File file1 = new File("/C:/Users/workspacememoire12/memoire/bin/memoire/class1.xml");
DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();

Document doc = dBuilder.parse(file);

System.out.println("Root element :" + doc.getDocumentElement().getNodeName());

if (doc.hasChildNodes()) {

printNote(doc.getChildNodes());

}

} catch (Exception e) {
System.out.println(e.getMessage());
}}
}

private static void printNote(NodeList nodeList) {

for (int count = 0; count < nodeList.getLength(); count++) {

Node tempNode = nodeList.item(count);

// make sure it's element node.
if (tempNode.getNodeType() == Node.ELEMENT_NODE) {

// get node name and value
System.out.println("\nNode Name =" + tempNode.getNodeName() + " [OPEN]");
System.out.println("Node Value =" + tempNode.getTextContent());

if (tempNode.hasAttributes()) {

// get attributes names and values
NamedNodeMap nodeMap = tempNode.getAttributes();

for (int i = 0; i < nodeMap.getLength(); i++) {

Node node = nodeMap.item(i);
System.out.println("attr name : " + node.getNodeName());
System.out.println("attr value : " + node.getNodeValue());

}

}

if (tempNode.hasChildNodes()) {

// loop again if has child nodes
printNote(tempNode.getChildNodes());

}

System.out.println("Node Name =" + tempNode.getNodeName() + " [CLOSE]");


try{


PrintWriter out = new PrintWriter(new FileWriter("ommmm.txt"));


out.println( ""+tempNode.getTextContent());
out.close();

PrintStream myconsole = new PrintStream(new File("C:/Users/workspacememoire12/aaaaa/src/class.txt"));
System.setOut(myconsole);
myconsole.print(" Node Name =" + tempNode.getNodeName() + " [CLOSE]");
myconsole.print( "\nNode Name =" + tempNode.getNodeName() + " [OPEN]");

}

catch(FileNotFoundException fx){
System.out.println(fx);} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

}

}

this code shown the resut in the consol but a need it in File

 

نشر على 14:56, الأحد 8 ماي 2016 By Meiem Amirat (9 points)
In Bases de données avancées


أجوبة (2)




جواب (1)

votes


نشر على 00:00, الخميس 1 جانفي 1970 by
In Bases de données avancées



هل لديك جواب ?