Java easyreport Import Excel, txt data txt by byte import (vii)

Source: Internet
Author: User

Sometimes the import TXT file is not necessarily used as a delimiter import, but by byte, character length import, such as UnionPay reconciliation file.

Import txt data


Name Age Account Score

Chen seeks 12 languages 67

Wang Lao 512 Chinese 80

Ke Jingteng 13 Languages 78

Shen Jiayi 14 Languages 88

Wang Small Base 15 language 60

Huang 12 Languages 54

Li 14 Languages 76

Cheng and Qing 13 language 58

Fang Anise 12 Languages 87

Shen 13 Languages 89

Lin Jia Mo 14 Languages 68

Zhao Ye 14 Languages 50

Sukey 12 Languages 78

Joe Burns 13 Languages 90


We use iso8859-1 single-byte encoding to read the file data, a Chinese character accounted for 2 bytes.


Import Demo

package example;


Import Java.io.File;

Import Java.io.FileInputStream;

Import java.util.List;

Import Java.util.Map;


Import model. Student;

Import Test. Abstracttxttest;


Import Com.easyReport.read.checker.GEValuePropertyChecker;

Import Com.easyReport.read.checker.LEValuePropertyChecker;

Import Com.easyReport.read.checker.PropertyChecker;

Import com.easyReport.read.temp.ReadTemp;

Import com.easyReport.read.temp.TxtBytePropertyTemp;

Import com.easyReport.read.temp.TxtReadTemp;


public class Testtxtbyte extends Abstracttxttest<student> {

@Override

public void Test () {

FileInputStream FileInputStream;

try {

FileInputStream = new FileInputStream (New File ("Testfile/test7.txt"));

Testreadbean (FileInputStream);

Testreadmap (FileInputStream);

Fileinputstream.close ();

} catch (Exception e) {

E.printstacktrace ();

}

}


@Override

Protected Readtemp bulidreadtemp () {

Template Batch setup construction method, read 10 rows at a time

Txtreadtemp readtemp = new Txtreadtemp (1,10);

Readtemp.setencode ("iso8859-1");

Readtemp.addpropertytemp (New Txtbytepropertytemp ("name", "name", 0,6));

Readtemp.addpropertytemp (New Txtbytepropertytemp ("Age", "ages", 6,8));

Readtemp.addpropertytemp (New Txtbytepropertytemp ("Account", "Course.name", 8,12));

Greater than or equal to 60 less than or equal to 80

Readtemp.addpropertytemp (New Txtbytepropertytemp ("Score", "Course.score", New propertychecker[]{

New Gevaluepropertychecker, New Levaluepropertychecker (80)

},12,14));

return readtemp;

}


@Override

protected void Writebeanlist (list<student> modellists) {

System.out.println ("--------------bean---------------");

for (Student s:modellists) {

System.out.println (S.getname () + "|"

+ s.getage () +s.getcourse (). GetName () + "|" +s.getcourse (). Getscore ());

}

}


@Override

protected void Writemaplist (list<map<string, object>> maplists) {

SYSTEM.OUT.PRINTLN ("--------------map---------------");

For (map<string, object> m:maplists) {

System.out.println (M.get ("name") + "|" + m.get ("age") + "|" + M.get ("course.name") + "|" + M.get ("Course.score");

}

}


}

The import template is shown in the Red Font section, we set the encoding to Iso8859-1, the read file will be read according to the set encoding input stream, the colleague uses the Txtbytepropertytemp property template to set the read start position and so on.

Operation Result:

--------------Bean---------------

Chen Yu |12 Chinese |67.0

Bachelor |12 Chinese |80.0

Ke jingteng |13 Chinese |78.0

Xiaojian |15 Chinese |60.0

Li |14 Chinese |76.0

--------------Bean---------------

Lin Jia mo |14 Chinese |68.0

Sukey |12 Chinese |78.0

Line 5th, the fractal value must be less than or equal to 80.0;

Line 7th, the value of the division must be greater than or equal to 60.0;

Line 9th, the value of the division must be greater than or equal to 60.0;

Line 10th, the fractal value must be less than or equal to 80.0;

Line 11th, the fractal value must be less than or equal to 80.0;

Line 13th, the value of the division must be greater than or equal to 60.0;

Line 15th, the fractal value must be less than or equal to 80.0;

We can also read files by character length.

Import data We make changes, name use 3 character length.

Name Age Account Score

Chen seeks 12 languages 67

Wang Lao 512 Chinese 80

Ke Jingteng 13 Languages 78

Shen Jiayi 14 Languages 88

Wang Small Base 15 language 60

Huang 12 Languages 54

Li 14 Languages 76

Cheng and Qing 13 language 58

Fang Anise 12 Languages 87

Shen 13 Languages 89

Lin Jia Mo 14 Languages 68

Zhao Ye 14 Languages 50

Sukey 12 Languages 78

Joe Burns 13 Languages 90


Import Demo

package example;


Import Java.io.File;

Import Java.io.FileInputStream;

Import java.util.List;

Import Java.util.Map;


Import model. Student;

Import Test. Abstracttxttest;


Import Com.easyReport.read.checker.GEValuePropertyChecker;

Import Com.easyReport.read.checker.LEValuePropertyChecker;

Import Com.easyReport.read.checker.PropertyChecker;

Import com.easyReport.read.temp.ReadTemp;

Import com.easyReport.read.temp.TxtBytePropertyTemp;

Import com.easyReport.read.temp.TxtReadTemp;


public class Testtxtbyte extends Abstracttxttest<student> {

@Override

public void Test () {

FileInputStream FileInputStream;

try {

FileInputStream = new FileInputStream (New File ("Testfile/test7.txt"));

Testreadbean (FileInputStream);

Testreadmap (FileInputStream);

Fileinputstream.close ();

} catch (Exception e) {

E.printstacktrace ();

}

}


@Override

Protected Readtemp bulidreadtemp () {

Template Batch setup construction method, read 10 rows at a time

Txtreadtemp readtemp = new Txtreadtemp (1,10);

/* Readtemp.setencode ("iso8859-1");

Readtemp.addpropertytemp (New Txtbytepropertytemp ("name", "name", 0,6));

Readtemp.addpropertytemp (New Txtbytepropertytemp ("Age", "ages", 6,8));

Readtemp.addpropertytemp (New Txtbytepropertytemp ("Account", "Course.name", 8,12));

Greater than or equal to 60 less than or equal to 80

Readtemp.addpropertytemp (New Txtbytepropertytemp ("Score", "Course.score", New propertychecker[]{

New Gevaluepropertychecker, New Levaluepropertychecker (80)

},12,14)); * *

Readtemp.addpropertytemp (New Txtbytepropertytemp ("name", "name", 0, 3));

Readtemp.addpropertytemp (New Txtbytepropertytemp ("Age", "ages", 3,5));

Readtemp.addpropertytemp (New Txtbytepropertytemp ("Account", "Course.name", 5,7));

Greater than or equal to 60 less than or equal to 80

Readtemp.addpropertytemp (New Txtbytepropertytemp ("Score", "Course.score", New propertychecker[]{

New Gevaluepropertychecker, New Levaluepropertychecker (80)

},7,9));

return readtemp;

}


@Override

protected void Writebeanlist (list<student> modellists) {

System.out.println ("--------------bean---------------");

for (Student s:modellists) {

System.out.println (S.getname () + "|"

+ s.getage () +s.getcourse (). GetName () + "|" +s.getcourse (). Getscore ());

}

}


@Override

protected void Writemaplist (list<map<string, object>> maplists) {

SYSTEM.OUT.PRINTLN ("--------------map---------------");

For (map<string, object> m:maplists) {

System.out.println (M.get ("name") + "|" + m.get ("age") + "|" + M.get ("course.name") + "|" + M.get ("Course.score");

}

}


}

No encoding is set and GBK encoding is used by default.

Operation Result:

--------------Bean---------------

Chen Yu |12 Chinese |67.0

Bachelor |12 Chinese |80.0

Ke jingteng |13 Chinese |78.0

Xiaojian |15 Chinese |60.0

Li |14 Chinese |76.0

--------------Bean---------------

Lin Jia mo |14 Chinese |68.0

Sukey |12 Chinese |78.0

Line 5th, the fractal value must be less than or equal to 80.0;

Line 7th, the value of the division must be greater than or equal to 60.0;

Line 9th, the value of the division must be greater than or equal to 60.0;

Line 10th, the fractal value must be less than or equal to 80.0;

Line 11th, the fractal value must be less than or equal to 80.0;

Line 13th, the value of the division must be greater than or equal to 60.0;

Line 15th, the fractal value must be less than or equal to 80.0;


This article is from "Rookie Bobo" blog, please be sure to keep this source http://zhangxiao2.blog.51cto.com/6342789/1591291

Java easyreport Import Excel, txt data txt by byte import (vii)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.