从数据库取出的内容是一个List,如何写进文本中?用java实现
解决方案 »
- Java 如何把word转化为swf或PDF
- 关于解析XML的问题,急!!!
- StringBuffer的capacity()方法
- 关于SWT Table控件绑定widgetSelected事件后,如何在该事件中获取鼠标点击的列是哪一列?
- JAVA程序
- 请教大家,我想通过JDBC访问一台安全性设置为Windows验证的SQL Server,请问如何写创建数据库连接的程序呀?
- 这个程序为何会出现两处错误提示:The constructor Date(int,int,int) is deprecated 和 The method getYear() from the type Date is de
- 求 21点(BlackJack)JAVA GUI 源程序
- tomcat 连接池配置成功,但是???????
- jdk1.4中logger的使用问题
- 最近做的一道小题,感觉有点费劲,大家可以试试
- 大家来帮我看看面试题
Customerinformation list = new Customerinformation();
list.getCustomerCompany();
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication3;import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;/**
*
* @author Administrator
*/
public class NewClass { public static void main(String[] args) {
ArrayList al = new ArrayList();
for (int i = 0; i < 100; i++) {
al.add(new Integer(i));
}
list2file(al, "C:\\A.TXT");
} public static boolean list2file(List l, String filepath) {
if (null == l) {
return false;
} FileWriter fr = null;
try { fr = new FileWriter(filepath);
Iterator it = l.iterator();
while (it.hasNext()) {
fr.write(it.next().toString());
fr.write("\n");
}
fr.close();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
if (null != fr) {
fr.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return true;
}
}
HttpServletRequest request, HttpServletResponse response) throws IOException {
List all = null;
try {
currentPage = Integer.parseInt(request.getParameter("cp"));
} catch (Exception e) {
}
try {
all = this.iuserworddao.queryAll();
}
catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String path=request.getRealPath(".");
FileWriter fw=null;
try { fw=new FileWriter(path + "\\WriteData.txt");
int i;
for(i=0;i<all.size();i++){
Userword pm = (Userword)all;
fw.write(pm.getUserword());
fw.write(pm.getUsertran());
fw.write("\n");
}
fw.close();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
if (null != fw) {
fw.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
request.setAttribute("all", all);
return mapping.findForward("list");
}
这段代码哪错了?竟然报错:java.lang.ClassCastException: java.util.ArrayList
然后输出就可以了
2.把取出来的对象一个个的拆封
3.通过java I/O写入到文本文档