Welcome to OStack Knowledge Sharing 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...