如何在java中使用分隔符分割数字

如何在java中使用分隔符分割数字,java,Java,我在一个文件中输入了一些格式的数字 106648 | 403481 747,826|369,456 758,122|365,637 503,576|808,710 325374 | 402513 不是,我想把数字格式化为 106,648 403,481 747,826 .. 等等,但我不能这么做,到目前为止我已经这么做了 public class MidPointSum { public static void main(String[] args) { File file=new

我在一个文件中输入了一些格式的数字

106648 | 403481 747,826|369,456 758,122|365,637 503,576|808,710 325374 | 402513

不是,我想把数字格式化为 106,648 403,481 747,826 .. 等等,但我不能这么做,到目前为止我已经这么做了

public class MidPointSum {

public static void main(String[] args) {

    File file=new File("D:/midpoint.txt");

    try{

        Scanner sc=new Scanner(file);

            while(sc.hasNext()){

                String value=sc.next();

                String getVal[]=value.split("|");
                for(int i=0;i<getVal.length;i++){

                    System.out.println(getVal[i]);
                }

            }

    }catch(FileNotFoundException e){
        System.err.println("File is not Found");
    }catch (Exception e){
        System.err.println("Another Exception");
    }

}
公共类中点和{
公共静态void main(字符串[]args){
File File=新文件(“D:/midpoint.txt”);
试一试{
扫描仪sc=新扫描仪(文件);
while(sc.hasNext()){
字符串值=sc.next();
字符串getVal[]=value.split(“|”);

对于(inti=0;iJava的split使用正则表达式,因此需要使用双转义管道:

String[] getVal=value.split("\\|");

如果它是一个普通的正则表达式,您无论如何都需要对其进行转义,但在java中,
“\”
是一个,由于像
\t
\n
这样的字符,因此需要进行双转义。

java的拆分使用一个正则表达式,因此您需要使用双转义管道:

String[] getVal=value.split("\\|");

如果它是一个普通的正则表达式,您无论如何都需要对它进行转义,但是在java中,
是一个,由于像
\t
\n
这样的字符,因此需要进行双转义。

<124;
是一个正则表达式元字符,需要对它进行转义,请尝试
“\\\”

是一个regex元字符,需要对其进行转义,请在拆分时尝试转义管道字符。如
.split(\\\\\”);
我还需要这对中的y坐标之和…有人能帮忙吗?拆分时尝试转义管道字符。如
.split(\\\\\”)
我还想要这对中y坐标的总和……有人能帮忙吗??