小春网

 找回密码
 注册账号
查看: 550|回复: 2
收起左侧

[IT 交流] framework.csv

[复制链接]
发表于 2011-4-19 23:02:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册账号

x

public void put(String s,boolean b) {

if (pw == null) {

throw new IllegalArgumentException(

"attempt to use a closed CSVWriter");

}

if (s == null) {

nl();

return;

}


if (wasPreviousField) {

pw.print(separator);

}

if (trim) {

s = s.trim();

}

if (s.indexOf(quote) >= 0) {

/* worst case, needs surrounding quotes and internal quotes doubled */

pw.print(quote);

for (int i = 0; i < s.length(); i++) {

char c = s.charAt(i);

if (c == quote) {

pw.print(quote);

pw.print(quote);

} else {

pw.print(c);

}

}

pw.print(quote);

} else if (b) {

/* need surrounding quotes */

pw.print(quote);

pw.print(s);

pw.print(quote);

} else {

if  (quoteLevel == 2 || (quoteLevel == 1

&& s.indexOf(' ') >= 0) || s.indexOf(separator) >= 0

|| s.indexOf("\n") >= 0 || s.indexOf("\r\n") >= 0) {

/* need surrounding quotes */

pw.print(quote);

pw.print(s);

pw.print(quote);

}  else {

/* ordinary case, no surrounding quotes needed */

pw.print(s);

}

}

/* make a note to print trailing comma later */

wasPreviousField = true;

}



public void put(String s) {

put(s,true);

}


/**

* Write a new line in the CVS output file to demark the end of record.

*/

public void nl() {

if (pw == null) {

throw new IllegalArgumentException(

"attempt to use a closed CSVSWriter");

}

/* don't bother to write last pending comma on the line */

pw.print("\r\n"); /*

* windows conventions since this is a windows

* format file

*/

wasPreviousField = false;

}



value=value+ temp + "\r\n";


value = StringUtils.replace(value, "\r", "");

value = StringUtils.replace(value, "\n", "");

value = StringUtils.convertSpectial(value);

csvWriter3.put(value);
csvWriter1.nl();








cvs.rar

2.51 KB, 下载次数: 3, 下载积分: 元气 -1 点

头像被屏蔽
发表于 2011-9-1 19:06:53 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

头像被屏蔽
发表于 2011-9-19 09:20:36 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

小春网
常务客服微信
微信订阅号
手机客户端
扫一扫,查看更方便! 快速回复 返回顶部 返回列表