-
-
Save btolfa/2357781 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.samples; | |
import java.io.BufferedReader; | |
import java.io.ByteArrayOutputStream; | |
import java.io.FileOutputStream; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.io.OutputStreamWriter; | |
import java.util.ArrayList; | |
import com.thoughtworks.xstream.XStream; | |
import com.thoughtworks.xstream.io.xml.DomDriver; | |
public class Writer { | |
public static void main(String[] args) throws IOException { | |
FileReader fiR = new FileReader( | |
"D:/My java workspace/sampleproject/tmp/AlmPos- ID.txt"); | |
BufferedReader buR = new BufferedReader(fiR); | |
buR.readLine();buR.readLine(); | |
// Объект-сериализатор | |
XStream xs = new XStream(new DomDriver()); | |
xs.autodetectAnnotations(true); | |
xs.aliasType("Element", Param.class); | |
FileOutputStream fs = new FileOutputStream( | |
"D:/My java workspace/sampleproject/tmp/AlmPos- ID.xml"); | |
ArrayList <Param> listElem = new ArrayList<Param>(); | |
listElem.add(new Param("tmp/AlmPos.xls", "0", 0, 0)); | |
String line; | |
for (int j = 0; (line = buR.readLine()) != null; j++) { | |
listElem.add((new Param("NameObj", line, Integer.parseInt(line = buR | |
.readLine()), Integer.parseInt(line = buR.readLine())))); | |
} | |
ObjectPars op = new ObjectPars(listElem); | |
// начало куска | |
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | |
java.io.Writer writer = new OutputStreamWriter(outputStream, "UTF-8"); | |
String xml = outputStream.toString("UTF-8"); | |
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); | |
xs.toXML(op, writer); | |
// конец | |
xs.toXML(op, fs); // Write to a file in the file system | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment