• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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: 60142
188
  • 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: 4776
52
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!