-1

I read the next answer about load file into java application.

I need to write a program that load .txt, which contains a list of records. After I parse it, I need to match the records (with conditions that I will check), and save the result to XML's file.

I am stuck on this issue, and I will happy for answer to next questions:

  1. How I load the .txt file into Java?
  2. After I load the file, how I can acsses to the information into it? for example, How I can asked if the first line of one of the records is equal to "1";
  3. How I export the result to XML's file.
Community
  • 1
  • 1
Adam Sh
  • 8,137
  • 22
  • 60
  • 75

2 Answers2

1
  1. Basic I/O
  2. Integer.parseInt(1stLine)
  3. There are a plethora of choices.
    1. Create POJO's to represent the records and write them using XMLEncoder
    2. SAX
    3. DOM..
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
1

one: you need a sample-code for reading a file line by line

two: the split-method of a string might be helpful. For instance getting the number of the first element if information is seperated by a space

String myLine;
String[] components = myLine.split(" ");
if(components != null && components.length >= 1) {
    int num = Integer.parseInt(components[0]);
    ....
}

three: you can just write it like any text-file, or use any XML-Writer you want

thomas
  • 5,637
  • 2
  • 24
  • 35