java-split text by row + qualification

Source: Internet
Author: User

Package First;import Java.io.bufferedreader;import Java.io.file;import java.io.filereader;import java.io.FileWriter Import Java.io.ioexception;import Java.io.inputstreamreader;public class Dealfile {public static void main (string[] args) throws Exception{bufferedreader in = new BufferedReader (new InputStreamReader (system.in));//Type the text name string FileName = In.readline (); FileManager Source = new FileManager (fileName); String head = Source.nextword (); String Word = null;int Count = 0;//int n = 0; String n = "-checkin"; fileName = filename.substring (0, Filename.length ()-4); FileWriter w = null;//with commas and newline characters as split string regex = "+ ', ' + ' |" + ' \ n '; while ((Word = Source.nextword ()) = null) {string[] STRs = Word.split (regex);//non-conforming if (Strs.length < 3 | |!strs[2 ].equals ("check-in")) continue;if (count = = 0) {w = new FileWriter (filename+n+ ". csv"); W.write (head);} SYSTEM.OUT.PRINTLN (n + ":" + count); W.write (word); ++count;} W.close ();}} Class Filemanager{int pos = 0; File F; FileReader Reader;boolean flag = false;publicFileManager (String filename) throws exception{f = new File (filename), reader = new FileReader (f);} Public String Nextword () throws Ioexception{if (flag) return null;char[] buf = new Char[1]; StringBuffer sb = new StringBuffer (), int len;do{len = Reader.read (BUF); Sb.append (Buf[0]);} while (' \ n '! = buf[0] && len! =-1); if (len = =-1) flag = True;return sb.tostring ();}}

java-split text by row + qualification

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.