问题:如何把大数据写进文件啊。我现在一个stringBuffer变量如何写进xml文件。现在的情况是我的stringBuffer是几百万条数据拼接的,我自己写的几百万条数据文件方法是这样的,但是失败了。
 try {
File fs= new File("d:/xyx.xml");
System.out.println("11111111111111111111111111111111");  //控制台有输出此句
if(!fs.exists())
 {
 fs.getParentFile().mkdirs();
System.out.println("2222222222222222222222222222222222");//控制台也有输出此句
 }
OutputStream os = new FileOutputStream(fs);
Writer w = new OutputStreamWriter(os, "UTF-8"); //编码格式需要指定
w.write(XMLData.toString());  //XMLData就是我拼接成的变量。   在这句就停止了。没有写进文件
System.out.println("333333333333333333333333333333333333");  //控制台没有输出此句,程序没有执行到这里了
w.close();
os.close();

大家帮忙看看。帮忙指定一下,怎么处理

解决方案 »

  1.   

    超长的stringBuffer变量如何写进xml文件。大家救命啊。此诚危急存亡之秋也
      

  2.   

    w.write(XMLData.toString()); //XMLData就是我拼接成的变量。 在这句就停止了。没有写进文件
    是还没写完吧?!几百万条数据,可能文件上G,上G的文件复制也要好长时间啊
      

  3.   

    首先改下思路吧,几百万条数据写进XML,真是疯狂。
      

  4.   

    如何读一条写一条?如何在xml文件上追加不占内存啊?
      

  5.   

    可能运行当中outofmemory了,把源数据截成几段分批写入吧。
      

  6.   

    w.write(XMLData.toString()); //XMLData就是我拼接成的变量。 在这句就停止了。没有写进文件
    为什么不把XMLData遍历输出呢转成那么大的字符串太疯狂了
      

  7.   

    $.get("EmployeesInformation.xml", function(xmlData) {

    /* 找到 Person 元素,然后用 each 方法进行遍历 */
    $(xmlData).find("Person").each(function() {
    string Person = $(this); /* 将当前元素复制给 Person */
    string FullName = Person.attr("FullName"); /* 获取 Person 的 FullName 属性 */
    string Corporation = Person.find("Corporation").text(); /* 获取 Person 中子元素 Corporation 的值 */
    string Description = Person.find("Description").text(); /* 获取 Person 中子元素 Description 的值 */
    string Products = Person.find("Products").text(); /* 获取 Person 中子元素 Products 的值 */ 。。
    }); });