• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to input data using BufferedReader and save as an external XML file?  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to create code which will be perform next actions?
• input data from the console
• create own type of data
• saving data in an array
• display on the screen
• saving to an external XML file

Java console input -> Example:

System.out.println ("Enter quantity of cars") // how many cars we will input
-> 1
(it means we have 1 car, which we will describe bellow, but may be more)

System.out.println("Enter car brand")
-> Ford

System.out.println("Enter color")
-> Red

System.out.println("Enter type")
-> Sedan

Then program will be save data as external XML file (C:\\cars.xml) (<1><brand>Ford</brand><color>Red</color><type>Sedan</type></1>)

In this task i need to use BufferedReader, Exceptions, Array, XML convert..

Thanks
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to thr Ranch

I wouldn't use a buffered reader for keyboard input, since Scanner was introduced 11 years ago. You can print a request and get the data from the keyboard in the appropriate format. Get that working and get the data into a Car class. Then consider writing the XML later.
 
Saloon Keeper
Posts: 3336
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your XML would look more like this:

I would have a Car class that has a String toXML() method. And perhaps a Cars class that manages a list of Cars; also with a String toXML() method. Cars.toXML() will be responsible for iterating through the list and calling the Car.toXML() method on each one.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!