Département d'Informatique

https://www.univ-soukahras.dz/fr/dept/cs

Matière: Bases de données avancées

  1. Information
  2. Questions
  3. E-Learning

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

 

Posté le 14:56, Sunday 8 May 2016 By
In Bases de données avancées


Réponses (2)




Réponse (1)

votes


Posté le 22:28, Monday 22 Jul 2024 by
In Bases de données avancées



Avez vous une réponse ?