Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

java - split(//s+) dont remove whitespaces

I need to read alot of files and insert the data into Ms sql. Got a file, it looks the texts are separated by //t. Split does not do the job, I have even tried with "//s+" as you can see in the code below

public void InsetIntoCustomers(final File _file, final Connection _conn)
{
    conn = _conn;
    try
    {

        FileInputStream fs = new FileInputStream(_file);
        DataInputStream in = new DataInputStream(fs);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));

        //String strline contains readline() from BufferedReader
        String strline;

        while((strline = br.readLine()) != null)
        {
            if(!strline.contains("#"))
            {

                String[] test = strline.split("//s+");


                if((tempid = sNet.chkSharednet(_conn, test[0] )) != 0)
                {
                  // do something
                }   
            }
        }

        // close BufferedReader
        br.close();
}

I need to know where in my String[] the data is placed in a file with 500k lines. But my Test[] get length 1 and all data from readline are on place 0.

Do I use split wrong ? Or are there other places I need to look?:

// Mir

haha - Thank you so much - why the hell didnt I see that myself. yeah ofc. iam using s+ at all other files. but thank for pointing it out.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The correct regex is \s+, with back-shashes instead of forward-slashes.

You could have still tried with \t


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...