Click here to Skip to main content
15,888,401 members
Home / Discussions / Java
   

Java

 
Questionget value inside array list in specific order Pin
sunil khichar28-Apr-14 7:36
sunil khichar28-Apr-14 7:36 
AnswerRe: get value inside array list in specific order Pin
jschell28-Apr-14 8:07
jschell28-Apr-14 8:07 
QuestionJSP VS ASP.net Pin
Kokkula27-Apr-14 18:53
Kokkula27-Apr-14 18:53 
AnswerRe: JSP VS ASP.net Pin
Prasad Khandekar11-Jun-14 0:27
professionalPrasad Khandekar11-Jun-14 0:27 
QuestionDatabase auto updates on JSP Pin
Kokkula27-Apr-14 11:13
Kokkula27-Apr-14 11:13 
Questionplease give me idea to code this algo in java for cloudsim tool Pin
Member 1077892327-Apr-14 10:51
Member 1077892327-Apr-14 10:51 
AnswerRe: please give me idea to code this algo in java for cloudsim tool Pin
jschell28-Apr-14 8:03
jschell28-Apr-14 8:03 
QuestionWrite to Xml file and Read on java Pin
Member 1077822527-Apr-14 2:39
Member 1077822527-Apr-14 2:39 
i want to create a java project:
Create objecte
create two function WriteXml () and ReadXml !
writeXml(): save informayion to xml file
ReadXml(): Read information frm xml file and show!
i use jdom 2.02
i do on 1 file "WriteReadXml.java"
-----code
Java
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.Text;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;

public class ReadWriteXml {
	public static void main (String[] args){
		writeXml ();
	//ReadXml();
	

}
	private static void ReadXml(){
		SAXBuilder builder = new SAXBuilder();
	
		Document readDoc = null;
		try {
			readDoc = builder.build(new File("./src/jdomMade.xml"));
		} catch (JDOMException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("Root:" + readDoc.getRootElement());
		
		System.out.println("Show:"+
				readDoc.getRootElement().getChild("show").getChildText("name"));
		System.out.println("show ID :" + readDoc.getRootElement().getChild("show").getChild("name").getAttributeValue("show_id) + "));
		Element root = readDoc.getRootElement();
		for (Element curEle : root.getChildren("show"));{
			Element curEle = null;
			System.out.println("show Name : " + 
		curEle.getChildText("name"));
			System.out.println("show ID : " 
		+curEle.getChild("name").getAttributeValue("show_id"));
			System.out.println(" on " + 
		curEle.getChildText("network")+"in the");
					System.out.println(curEle.getChild("network").getAttributeValue("country"));
		}
		
	}
		
		
	
private static void writeXml () {

	try{
	Document doc = new Document();
	Element theRoot = new Element ("tvshows");
	doc.setRootElement(theRoot);
	Element show = new Element ("show");
	Element name = new Element ("name");
	name.setAttribute("show_id","shows_001");
	name.addContent(new Text ("Game program"));
	Element network = new Element ("network");
	network.setAttribute("C***ry","TN");
	network.addContent(new Text ("TNN"));
	show.addContent(name);
	show.addContent(network);
	theRoot.addContent(show);
	
	//// second example
	
	Element show2 = new Element ("show");
	Element name2 = new Element ("name");
	name2.setAttribute("show_id","shows_002");
	name2.addContent(new Text ("Kids prgram"));
	
	Element network2 = new Element ("network");
	network2.setAttribute("C***ry","FR");
	network2.addContent(new Text ("TNT"));
	show2.addContent(name2);
	show2.addContent(network2);
	theRoot.addContent(show2);
	
	XMLOutputter xmlOutput = new XMLOutputter (Format.getPrettyFormat());
	xmlOutput.output(doc, new FileOutputStream(new File (".src/jdomMade.xml")));
	System.out.println("Wrote to file");
	}
    catch (Exception ex){
		
		ex.printStackTrace();
}

}
}
----
_________________________
error is :


XML
at java.io.FileOutputStream.<init>(Unknown Source)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at ReadWriteXml.writeXml(ReadWriteXml.java:84)
    at ReadWriteXml.main(ReadWriteXml.java:16)



tnx for answer me http://s.codeproject.com/script/Forums/Images/thumbs_up.gif

http://s.codeproject.com/script/Forums/Images/smiley_doh.gif
AnswerRe: Write to Xml file and Read on java Pin
Prasad Khandekar11-Jun-14 0:44
professionalPrasad Khandekar11-Jun-14 0:44 
QuestionHow to install a project using Jboss Pin
Member 1077205124-Apr-14 1:40
Member 1077205124-Apr-14 1:40 
Questionjava.net.SocketException: Software caused connection abort: socket write error Exception after writing some values Pin
Nosheen Javed23-Apr-14 21:20
Nosheen Javed23-Apr-14 21:20 
QuestionRead PDF tables using iText Pin
raesark23-Apr-14 0:25
raesark23-Apr-14 0:25 
AnswerRe: Read PDF tables using iText Pin
TorstenH.23-Apr-14 1:10
TorstenH.23-Apr-14 1:10 
GeneralRe: Read PDF tables using iText Pin
raesark23-Apr-14 1:28
raesark23-Apr-14 1:28 
GeneralRe: Read PDF tables using iText Pin
TorstenH.23-Apr-14 1:59
TorstenH.23-Apr-14 1:59 
GeneralRe: Read PDF tables using iText Pin
raesark23-Apr-14 3:19
raesark23-Apr-14 3:19 
GeneralRe: Read PDF tables using iText Pin
TorstenH.23-Apr-14 4:03
TorstenH.23-Apr-14 4:03 
QuestionApplet Automation Pin
Member 909935222-Apr-14 20:06
professionalMember 909935222-Apr-14 20:06 
AnswerRe: Applet Automation Pin
TorstenH.23-Apr-14 1:11
TorstenH.23-Apr-14 1:11 
GeneralRe: Applet Automation Pin
Member 909935223-Apr-14 1:41
professionalMember 909935223-Apr-14 1:41 
QuestionConstructor problem Pin
john_meee21-Apr-14 23:16
john_meee21-Apr-14 23:16 
AnswerRe: Constructor problem Pin
TorstenH.23-Apr-14 1:22
TorstenH.23-Apr-14 1:22 
AnswerRe: Constructor problem Pin
vipul57412-Jun-14 21:46
vipul57412-Jun-14 21:46 
QuestionIs there a pre-defined mthod in java works same as GetFontData pre-defined function in C++ Pin
f2620-Apr-14 20:44
f2620-Apr-14 20:44 
AnswerRe: Is there a pre-defined mthod in java works same as GetFontData pre-defined function in C++ Pin
TorstenH.23-Apr-14 1:25
TorstenH.23-Apr-14 1:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.