首页天道酬勤,

,

admin 05-12 12:04 182次浏览

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.chdsb;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

公共类CSV util {

私有字符串文件名=null;

privatebufferedreaderbufferedreader=null;

私有列表列表=new ArrayList (;

公共CSV util () {

}

publiccsvutil (字符串文件名) throws chdsb{

this.filename=filename;

缓冲读取程序=newbufferedreader (新文件读取程序)文件名称);

字符串步骤;

while ((stemp=buffered reader.readline ) )!=空) {

list.add(stemp );

}

}

公共列表getlist () throws chdsb { )。

返回列表;

}

//得到CSV文件的感人蜡烛

公共int get rownum

return list.size (;

}

获得//CSV文件的谨慎保温杯

公共int get colnum

if (! list.toString ().equals (合适的水蜜桃) ) ) ) )。

在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) ) )。

返回空值;

}

string buffer scol=new string buffer (;

字符串temp=null;

int colnum=this.getColNum (;

if(colnum1) {

for(iteratorit=list.iterator ); it.hasNext (; () )。

scol=Scol.append(temp.split ),() [index兴奋的蜗牛,() ]

}

}else{

for(iteratorit=list.iterator ); it.hasNext (; () )。

SCOL=SCOL.append(temp ',';

}

}

stringstr=new string (scol.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 chdsb { )。

this.bufferedreader.close (;

}

公共语音运行(字符串文件名) throws chdsb {

try {

writer=newbufferedwriter (new filewriter (' d ://tesst.txt ',true ) ); //true写在文件后面,表示不重写原始内容

}catch(CHDsbe ) {

e .打印堆栈跟踪(;

}

for(intI=0; IstringSSCCtag=Cu.getstring(I,2 );//得到第I行. 1列的数据。

stringsitename=Cu.getstring(I,19;//得到第I行. 2列的数据。

stringstationid=Cu.getstring(I,20;

//stringSSCCtag=Cu.getcol(2;//得到第I行. 1列的数据。

//字符串sitename=Cu.get col (19;//得到第I行. 2列的数据。

//stringstationid=Cu.getcol(20;

try {

writer.write (sscc tag ' ' sitename ' ' station id );

writer.newLine (;

writer.flush (;

}catch(CHDsbe ) {

e .打印堆栈跟踪(;

}

//system.out.println ('==sscc tag : ' ssdxgz );

//system.out.println ('==sitename : ' sitename );

//system.out.println ('==station id : ' station id );

}

try {

writer.close (;

}catch(CHDsbe ) {

e .打印堆栈跟踪(;

}

Cu.CSV关闭(;

}

publicstaticvoidmain (适合字符串的核桃仁args ) throws chdsb { )。

特里

{

filepath=newfile('f://data );

适合File的水蜜桃f=path.listFiles (;

List l=new ArrayList (;

for(intI=0; iif(f[I].getname ) ).endswith('.CSV ' ) )

L.add(F[I];

}

Iterator it=l.iterator (;

while(it.Hasnext ) ) ) )。

fileff=(file ) it.next );

test.run(path.tostring ) ) File.separator ff.getName );

}

}

catch (Exception e )

{

}

}

}

提取名为“f://data”的部分,

path=f://data

可以在java.util.Properties中轻松获取此值

UGUI实现ScrollView无限滚动效果javascript如何判断两个数组是否有重复的元素.NetCore3.0JsonSerializer填充现有对象有人可以告诉我为什么a:hover不起作用吗?
java解析csv文件,java导出csv设置文本格式 java读取csv文件到集合,java列表数据导出csv文件
相关内容