0

我正在尝试生成一个 csv 文件。在此,当我添加图像时,它将存储在服务器上,然后是该图像的路径/链接。我正在尝试解析它并写入 csv 文件。这个链接长度很大。所以在 csv 中,它把这条路径放在线上,然后再放新的。如何解决这个问题?

Java 代码:

        File fXmlFile = new File("d:/Eff_SOR/formdata.xml");
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(fXmlFile);
        doc.getDocumentElement().normalize();
        System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
        NodeList nList = doc.getElementsByTagName("record");
        System.out.println("----------------------------");
        List< Map<String, String>> list = new ArrayList<Map<String,String>>();

        for (int temp = 0; temp < nList.getLength(); temp++) {
             Map<String, String> map = new HashMap<String, String>();
             Node nNode = nList.item(temp);
             if (nNode.getNodeType() == Node.ELEMENT_NODE) {
             Element eElement = (Element) nNode;
             map.put("Original_Price_signature", eElement.getElementsByTagName("original_price_signature").item(0).getTextContent());
             list.add(map);               
              }
        }       
        generateCsvFile("d:\\SOR\\SOR.csv", list );


 .......................
 ............................
 private static void generateCsvFile(String sFilename, List< Map<String, String>>  test) {
    try {
        FileWriter writer = new FileWriter(sFilename);         
               for (Map<String, String> map : test) {          


        Iterator iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String,String> mapEntry = (Map.Entry<String,String>) iterator.next();
           //ystem.out.println("key: " + mapEntry.getKey() + ", value:" + mapEntry.getValue());

            writer.append(mapEntry.getValue());
            writer.append(",");
            iterator.remove();
        }
        writer.append(LINE_BREAK);
        }
        writer.flush();
        writer.close();
    }catch(Exception e){

    }
 }
4

0 回答 0