1

I have tried split with some other texts, its working fine there but not here. Can someone tell me what I did wrong here?

private static String fileName = "jjjj.txt";

private static String userName = "xxxx";
private static String password = "yyyy";
public static void main(String args[]){

    String info = "UserName" +"|"+ userName + "|" + password + "|" + fileName;
    String tempStr[] = info.split("|");
    System.out.println(tempStr[0]);
    System.out.println(tempStr[1]);
    System.out.println(tempStr[2]);
    System.out.println(tempStr[3]);
}

I am getting output as :

U
s
e

What should I do to get the output as:

UserName
xxxx
yyyy
jjjj.txt
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199

1 Answers1

6

You have to escape the | in your regular expression. This should work:

String tempStr[] = info.split("\\|");
user432
  • 3,506
  • 17
  • 24