Java用dom4j把生成的数据储存到xml文件相同时,出现问题不知道怎么回事新手,求答
bt_create2.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(A...
bt_create2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub try { if(file!=null){ OutputFormat format = OutputFormat.createPrettyPrint(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); //PrintWriter pw=new PrintWriter(fw); Document document=DocumentHelper.createDocument(); Element root = document.addElement("ROOT"); for(int i=1;i<=1000;i++) { Element data = root.addElement("DATA"); for(int k=1;k<=n;k++) { if(k==1){ BigDecimal aa=new BigDecimal(Math.random()*(df[k].max-df[k].min)+df[k].min); Element one = data.addElement("ONE"); one.setText(String.valueOf(aa.setScale(df[k].dot,BigDecimal.ROUND_HALF_UP)));} if(k==2){ BigDecimal aa=new BigDecimal(Math.random()*(df[k].max-df[k].min)+df[k].min); Element two = data.addElement("TWO"); two.setText(String.valueOf(aa.setScale(df[k].dot,BigDecimal.ROUND_HALF_UP))); } if(k==3){ BigDecimal aa=new BigDecimal(Math.random()*(df[k].max-df[k].min)+df[k].min); Element three = data.addElement("THREE"); three.setText(String.valueOf(aa.setScale(df[k].dot,BigDecimal.ROUND_HALF_UP))); } if(k==4){ BigDecimal aa=new BigDecimal(Math.random()*(df[k].max-df[k].min)+df[k].min); Element four = data.addElement("FOUR"); four.setText(String.valueOf(aa.setScale(df[k].dot,BigDecimal.ROUND_HALF_UP))); } if(k==5){ BigDecimal aa=new BigDecimal(Math.random()*(df[k].max-df[k].min)+df[k].min); Element five = data.addElement("FIVE"); five.setText(String.valueOf(aa.setScale(df[k].dot,BigDecimal.ROUND_HALF_UP))); } if(k==6){ BigDecimal aa=new BigDecimal(Math.random()*(df[k].max-df[k].min)+df[k].min); Element six = data.addElement("SIX"); six.setText(String.valueOf(aa.setScale(df[k].dot,BigDecimal.ROUND_HALF_UP))); } XMLWriter output=new XMLWriter(bw); output.write(document); output.close(); } format.setNewlines(true); } //String xml=root.asXML(); //System.out.println(xml); //pw.write(xml); //pw.close(); fw.close(); bw.close(); JOptionPane.showMessageDialog(null, "已生成xml文件"); } } catch (IOException e) { e.printStackTrace(); } } });
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询