The original file content is this:
1000|1.0.0313|20140814|2 Bank Serial number | transaction Time | Transaction date | Bank Virtual Account | Account number | account Type | name | gender | Voucher Type | ID no. | Certificate validity period | telephone | email | | Third-party product code 31301201408140000002802313000000|20140814101832|20140814|00000000002014081200000000000355| 6216920000065381|01|000|0|00|371321198812266128|20150202|15811111111| [Email protected]| | 11| | |8| 000888
We save it as UTF-8 format and read the file with the following Java code
Package Com.szkingdom.leejun;import Java.io.file;import Java.io.fileinputstream;import java.io.IOException;import Java.util.arrays;public class Filebomtest {public static void main (string[] args) throws IOException {File File = new file ("F:\\haha.txt"); FileInputStream fileinputstream=new fileinputstream (file); byte[] B=new byte[1024];byte[] b=new byte[0];int read =-1; while ((Read=fileinputstream.read (b)) >-1) {int i=b.length; B=arrays.copyof (B, B.length+read); for (int j=0;j<read;j++) {b[i+j]=b[j];}} System.out.println (New String (B, "UTF-8"));}}
This is how the console displays:
1000|1.0.0313|20140814|2 Bank Serial number | Transaction Time | Trading Date | Bank Virtual Account | Account number | account Type | name | gender | Voucher Type | ID no. | Certificate validity period | telephone | email | province | city | Third-party product code 31301201408140000002802313000000|20140814101832|20140814|00000000002014081200000000000355| 6216920000065381|01|000|0|00|371321198812266128|20150202|15811111111| [Email protected]| | 11| | |8| 000888
One more on the front? Why, this is why. The reason is actually very simple, when we re-save Windows under the last time Windows added BOM header to UTF-8. Causes a read exception to occur. We open the file with 16 binary to see: EF BB BF these several prefixes. Now that you know it's there? The principle of the number, then we just need to determine whether there is a prefix, if any, then skip the corresponding characters on the line. Or it can be read with an external tool class.
After you copy the UTF-8 file with a Java program, it appears at the beginning.