请问
从数据库中,读出一个记录字符窜,strItem,
请问JSP中 如何往一个指定文件名的CSV文件(Excel文件)里写数据(strItem)?
假设文件名为c:text.csv
从数据库中,读出一个记录字符窜,strItem,
请问JSP中 如何往一个指定文件名的CSV文件(Excel文件)里写数据(strItem)?
假设文件名为c:text.csv
解决方案 »
- java中如何用js判断发送短信的字数超过70字为第二条短信
- jsp里面怎样知道客户端浏览器已经关闭断开了连接
- jsp聊天室里的私聊怎么实现
- 当数据库连接关掉以后,结果集和STATEMENT是不是自动关掉了??
- 对session对象的方法session.setAttribute和session.getAttribute的问题?
- jsp有几种错误代码 像500和404这样的。
- RequestDispatcher的forward问题(憋了一个上午了)
- 关于jsp页面中,数据库的记录增加时,怎么自动更新啊?
- JSP中模仿论坛发帖功能的问题
- 外网访问,很慢,. 如图...
- 客户端的java虚拟机会不会影响网站访问速度
- jsp中如何获取客户端浏览器信息
import java.util.*;public class CsvFileImport
{
private static String line = null;
BufferedReader in = null;/**
* CsvFileImport constructor comment.
*/
public CsvFileImport() {
super();
}public static void main(String args[]){try
{String fileName = "C:\\javatest\\CSVImport.csv";
BufferedReader in = new BufferedReader(new FileReader(fileName));
while((line = in.readLine()) != null){
StringTokenizer st=new StringTokenizer(line,",");
int tokenCount=0;
while(st.hasMoreTokens()){
tokenCount++;
String token=st.nextToken();
if(token.indexOf("\"")!=-1){
//this token contains a " , so we should read the next one too
String next;
while((next=st.nextToken()).indexOf("\"")==-1)
token+=next;//ugly,might use a stringbuffer
//it might also break if csv incorrectly formed
}
System.out.println(token);//you now have your token here, do extra processing with it
if(tokenCount==3){//this is the salary
try{
double value=Double.parseDouble(token);
value+=1000;
token=String.valueOf(value);
}catch(NumberFormatException e) {}
}
//now put the token in another file...
//TODO Wink
}
}}catch (IOException e)
{
System.err.println("...");
}}
}
http://blog.csdn.net/lcllcl987/archive/2005/01/12/250129.aspx
可以读取和修改office的文档,包括word,excel....
这里面有你要的java读写excel文件
姓名 年龄
a 1
b 2
c 3
这些数据写在csv文件中其实就是
姓名,年龄
a,1
b,2
c,3
这样的文本文件
String line = "姓名,年龄";
line = line + "\r\n";
out.write(line);
line = "a,1";
line = line + "\r\n";
out.write(line);
line = "b,2";
line = line + "\r\n";
out.write(line);
line = "c,3";
line = line + "\r\n";
out.write(line);
out.flush();
out.close();