mysql txt表格格式转换_[导入]mysql 导出文本数据转换展现格式

package

uu;

import

java.io.BufferedReader;

import

java.io.File;

import

java.io.FileInputStream;

import

java.io.FileOutputStream;

import

java.io.InputStreamReader;

import

java.io.OutputStreamWriter;

import

java.util.ArrayList;

import

java.util.HashMap;

import

java.util.List;

import

java.util.Map;

import

java.util.regex.Pattern;

public

class

MainExc {

//

数据文本

static

String filePath

=

"

smsservice.data

"

;

//

输出文本

static

String outfile

=

"

outfile.html

"

;

//

输出 文本格式

static

String charset

=

"

GBK

"

;

//

数据逻辑 展现

static

Map

<

Pattern, String

>

map

=

new

HashMap

<

Pattern, String

>

();

static

{

map.put(Pattern.compile(

"

^XZT

"

),

"

sina

"

);

。。。。。

}

//

类型定义

static

Map

<

Pattern, String

>

maptype

=

new

HashMap

<

Pattern, String

>

();

static

{

maptype.put(Pattern.compile(

"

^3P45

"

),

"

客户端

"

);

maptype.put(Pattern.compile(

"

^6930

"

),

"

图表

"

);

......

}

//

禁止展现

static

List

<

Pattern

>

listNo

=

new

ArrayList

<

Pattern

>

();

static

{

listNo.add(Pattern.compile(

"

^9588Command$

"

));

listNo.add(Pattern.compile(

"

^5kjsCommand$

"

));

listNo.add(Pattern.compile(

"

^529901001011021$

"

));

listNo.add(Pattern.compile(

"

^529901001011022$

"

));

}

public

static

void

main(String[] args)

throws

Exception {

//

read

InputStreamReader read

=

new

InputStreamReader(

new

FileInputStream(MainExc.

class

.getClassLoader().getResource(

filePath).getPath()), charset);

//

writer

if

(MainExc.

class

.getClassLoader().getResource(outfile)

==

null

) {

new

File(MainExc.

class

.getClassLoader().getResource(

"

.

"

).getPath()

+

"

/outfile.html

"

).createNewFile();

}

OutputStreamWriter writer

=

new

OutputStreamWriter(

new

FileOutputStream(MainExc.

class

.getClassLoader()

.getResource(outfile).getPath()), charset);

//

内存 装载 处

List

<

Map

<

String, String

>>

datas

=

new

ArrayList

<

Map

<

String, String

>>

();

StringBuffer buffer

=

new

StringBuffer();

BufferedReader reader

=

new

BufferedReader(read);

String stmp

=

null

;

List

<

String

>

colName

=

new

ArrayList

<

String

>

();

//

得到 列名

if

((stmp

=

reader.readLine())

!=

null

&&

!

stmp.trim().equals(

""

)) {

//

split - > Tab

for

(String stmp2 : stmp.split(

"

"

)) {

colName.add(stmp2);

}

}

//

列数据收集

while

((stmp

=

reader.readLine())

!=

null

&&

!

stmp.trim().equals(

""

)) {

Map

<

String, String

>

data

=

new

HashMap

<

String, String

>

();

String[] sdata

=

stmp.split(

"

"

);

for

(

int

i

=

0

; i

<

colName.size(); i

++

) {

data.put(colName.get(i), sdata[i]);

}

datas.add(data);

}

//

writer

writer.append(

"

"

);

writer.append(

"

"

+

"

通道伙伴

"

+

"

指令

"

+

"

长号码

"

+

"

资费

"

+

"

业务类型(图表/客户端)

"

+

"

\n

"

);

//

通道伙伴 指令 长号码 资费 业务类型(图表?客户端?)

wfor:

for

(Map

<

String, String

>

mtmp : datas) {

for

(Pattern ptmp : listNo) {

if

(ptmp.matcher(mtmp.get(

"

command

"

)).find()) {

continue

wfor;

}

}

String hzhb

=

""

;

for

(Pattern ptmp : map.keySet()) {

if

(ptmp.matcher(mtmp.get(

"

command

"

)).find()) {

hzhb

=

map.get(ptmp);

}

}

String type

=

""

;

for

(Pattern ptmp : maptype.keySet()) {

if

(ptmp.matcher(mtmp.get(

"

command

"

)).find()) {

type

=

maptype.get(ptmp);

}

}

writer.append(

"

"

+

"

"

+

hzhb

+

"

"

+

"

"

+

mtmp.get(

"

command

"

)

+

"

"

+

"

"

+

mtmp.get(

"

num

"

)

+

"

"

+

"

"

+

mtmp.get(

"

money

"

)

+

"

"

+

"

"

+

type

+

"

"

+

"

\n

"

);

}

writer.append(

"

\n

"

);

//

save

writer.flush();

writer.close();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值