Java 输入数据有问题

Java 输入数据有问题,java,Java,我写了一个程序,应该以某种方式打印输入。现在我正在使用逗号分割输入。但是,输入列表以以下形式提供给我: 10.10.4.0-24 10.100.0.0-16 10.102.0.0-16 10.106.0.0-20 10.117.0.0-16 10.118.0.0-16 10.15.128.0-24 而且名单也要长得多。我刚刚在它们之间插入了逗号,并将它们放在同一行上,但这相当乏味。我尝试使用字符串rawdata[]=raw.split(“”)而不是字符串rawdata[]=raw.split(

我写了一个程序,应该以某种方式打印输入。现在我正在使用逗号分割输入。但是,输入列表以以下形式提供给我:

10.10.4.0-24
10.100.0.0-16
10.102.0.0-16
10.106.0.0-20
10.117.0.0-16
10.118.0.0-16
10.15.128.0-24
而且名单也要长得多。我刚刚在它们之间插入了逗号,并将它们放在同一行上,但这相当乏味。我尝试使用
字符串rawdata[]=raw.split(“”)
而不是
字符串rawdata[]=raw.split(“,”)但是它没有按照我的意思工作。它不是按如下方式打印每个输入的所需输出:

 Enter ip addresses separated by commas, no spaces(e.g. 10.105.128.0-19,10.120.192.0-22).
10.10.4.0-24
10.100.0.0-16
10.102.0.0-16
10.106.0.0-20
10.117.0.0-16
10.118.0.0-16

set network virtual-router VR-TZ7 routing-table ip static-route 10.118.0.0-16-TSA_TZ nexthop ip-address 10.22.238.99
set network virtual-router VR-TZ7 routing-table ip static-route 10.118.0.0-16-TSA_TZ interface ethernet1/7
set network virtual-router VR-TZ7 routing-table ip static-route 10.118.0.0-16-TSA_TZ metric 10
set network virtual-router VR-TZ7 routing-table ip static-route 10.118.0.0-16-TSA_TZ admin-dist 10
set network virtual-router VR-TZ7 routing-table ip static-route 10.118.0.0-16-TSA_TZ destination 10.118.0.0/16
在我的程序中是否有一个分隔符可以用来处理这种格式的数字

我的计划如下:

import java.util.Scanner;
public class POPprogTSA
{  
public static void main(String[] args)
{

Scanner s = new Scanner(System.in);
System.out.println("Enter ip addresses separated by commas, no spaces(e.g. 10.105.128.0-19,10.120.192.0-22).");
String raw= s.nextLine();
String rawdata[]=raw.split(",");
/*set network virtual-router VR-TZ7 routing-table ip static-route 10.10.4.0-24-TSA_TZ nexthop ip-address 10.22.238.99
set network virtual-router VR-TZ7 routing-table ip static-route 10.10.4.0-24-TSA_TZ interface ethernet1/7
set network virtual-router VR-TZ7 routing-table ip static-route 10.10.4.0-24-TSA_TZ metric 10
set network virtual-router VR-TZ7 routing-table ip static-route 10.10.4.0-24-TSA_TZ admin-dist 10
set network virtual-router VR-TZ7 routing-table ip static-route 10.10.4.0-24-TSA_TZ destination 10.10.4.0/24
*/  
//TSA
for (int i = 0; i<= rawdata.length-1; i++)
{ 

 System.out.println("set network virtual-router VR-TZ7 routing-table ip static-route " + rawdata[i] + "-TSA_TZ nexthop ip-address 10.22.238.99");
 System.out.println("set network virtual-router VR-TZ7 routing-table ip static-route " + rawdata[i] + "-TSA_TZ interface ethernet1/7");
 System.out.println("set network virtual-router VR-TZ7 routing-table ip static-route " + rawdata[i] + "-TSA_TZ metric 10");
 System.out.println("set network virtual-router VR-TZ7 routing-table ip static-route " + rawdata[i] + "-TSA_TZ admin-dist 10");
 System.out.println("set network virtual-router VR-TZ7 routing-table ip static-route " + rawdata[i] + "-TSA_TZ destination " +(rawdata[i].replace("-","/")));
 System.out.println(" ");





}     
}


}

任何建议都将不胜感激

一个选项是让用户一次输入一个输入,但持续提示他们(使用
nextLine()
阅读),直到输入单词“end”。然后,您可以复制一个行分隔列表并将其粘贴到控制台中;在末尾键入“end”

或者,如果您希望用户能够将一组内容复制并粘贴到一行中,则可以使用
.split([\\s]+”)
允许条目之间存在任意数量的空格(包括换行符;尽管
nextLine()
无论如何都会占用换行符)


另一个选项是将列表存储在文本文件中。然后,您可以提示用户输入要导入的文件的名称。然后可以打开文件并逐行读取。

是否希望10.10.4.0-24成为一个令牌?还是你在拆分“10.10.4.0-24”?您能否展示一些手动拆分输出的示例,以便我们知道您到底在寻找什么?是的,10.10.4.0-24是一个标记。如果输入为“10.10.4.0-24,10.100.0.0-16”,则应将其拆分为“10.10.4.0-24”和“10.100.0.0-16”,但我想知道是否可以更改分隔符,以便我不必在每个地址之间插入逗号并将其放在同一行。Re:
.split(“”
:您能否澄清“它不按我的意思工作”?是否尝试按换行符“\n”拆分?您正在读取的行数是否始终相同?
set network virtual-router VR-TZ7 routing-table ip static-route 10.10.4.0-24-TSA_TZ nexthop ip-address 10.22.238.99
set network virtual-router VR-TZ7 routing-table ip static-route 10.10.4.0-24-TSA_TZ interface ethernet1/7
set network virtual-router VR-TZ7 routing-table ip static-route 10.10.4.0-24-TSA_TZ metric 10
set network virtual-router VR-TZ7 routing-table ip static-route 10.10.4.0-24-TSA_TZ admin-dist 10
set network virtual-router VR-TZ7 routing-table ip static-route 10.10.4.0-24-TSA_TZ destination 10.10.4.0/24