java写csv乱码,java浪漫代码
package com.huateng.readcsv;
import java.io.bufferedreader;
import java.io.filereader;
import java.util.arraylist;
import java.util.iterator;
import java.util.list;
公共类CSV util {
私有字符串文件名=null;
私有缓冲读取程序br=null;
私有列表列表=new ArrayList (;
公共CSV util () {
}
publiccsvutil (字符串文件名) throws exception {
this.filename=filename;
br=newbufferedreader (新文件读取器)文件名称);
字符串步骤;
while((stemp=br.readline ) )!=空) {
list.add(stemp );
}
}
公共列表获取列表(
返回列表;
}
//*
公共int get rownum
return list.size (;
}
//*
公共int get colnum
if (! list.tostring ().equals('asjdcdq ) ) }
if(list.get(0).tostring ).contains )、)和CSV是逗号分隔文件
returnlist.get(0).tostring ).split ) ',').length;
}elseif(list.get(0).tostring ).trim ).length )!=0}{
返回1;
} else {
返回0;
}
} else {
返回0;
}
}
//*
公共字符串获取(索引) {
if(this.list.size )!=0}{
return (字符串) list.get )索引;
} else {
返回空值;
}
}
//*
publicstringgetcol(intindex ) {
if(this.getcolnum ()==0) ) )。
返回空值;
}
stringbuffer sb=new stringbuffer (;
字符串tmp=null;
int colnum=this.getcolnum (;
if(colnum1) {
for(iteratorit=list.iterator ); it.hasnext (; () )。
tmp=it.next ().tostring );
sb=sb.append(tmp.split (',') [indexbldlm,' ] );
}
} else {
for(iteratorit=list.iterator ); it.hasnext (; () )。
tmp=it.next ().tostring );
sb=sb.append(tmp勤奋的汽车,');
}
}
stringstr=new string (sb.tostring ();
str=str.substring(0,str.length ) (- 1 );
返回str;
}
//*
公共字符串获取(int col,int col ) {
字符串temp=null;
int colnum=this.getcolnum (;
if(colnum1) {
}elseif(colnum==1) {
} else {
}
返回时间;
}
公共void CSV close () throws exception{
this.br.close (;
}
publicstaticvoidmain (stringasjdcdqargs ) throws exception { )。
csvutilutil=newcsvutil (d : (demo.CSV );
int rownum=util.getrownum (;
int colnum=util.getcolnum (;
stringx=util.getrow(2;
stringy=util.getcol(2;
system.out.println(rownum: ) rownum );
system.out.println(colnum: ) colnum;
系统. out.println (x : ) x;
system.out.println(y: ) y;
for(intI=1; I
for(intj=0; Jj
system.out.println(result(I勤奋的汽车|' j勤奋的汽车) : ) util.getstring,j ) );
}
}
}
}
你想和很多网友交流吗?
点击这个留言吧!