用Java读取多个命令行 [英] Read Multiple Commandlines in Java

查看:76
本文介绍了用Java读取多个命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从命令行读取输入。

我的输入有点像这样:



I am trying to read inputs from command line.
My Input is somewhat like this :

# the total size of physical memory (units are B, KB, MB, GB)
512MB 2 # the following are memory allocations
{
abc = alloc(1KB);
{
y_ = alloc(128MB);
x1 = alloc(128MB);
y_ = alloc(32MB);
for (i = 0; i < 256; i++) abc[i] = alloc(512kB);
x1 = alloc(32MB); x2 = alloc(32MB); x3 = alloc(32MB);
x1.next = x2; x2.next = x3; x3.next = x1;
}
abc = alloc(256MB);
}





我如何访问每一行?



任何帮助???



How can I access each line ?

Any Help???

推荐答案

您好,



试试这个:



Hi,

Try this:

public class Main {
	public static void main(String[] args) {
		String initialString = "line1\nline2\nline3";
		System.out.println(initialString);
		System.out.println();
		
		// Get each line of your initialString
		String[] eachString = initialString.split("\n");
		for(int i = 0; i < eachString.length; i++) {
			System.out.println("My line " + i + ": " + eachString[i]);
		}
	}
}





[更新]





[UPDATE]

String InputInstArray[] = new String[100];
BufferedReader InstStorageBuf= new BufferedReader(new InputStreamReader(System.in));

//Read Input Instructions
for(int getlnst=0; getlnst<100; getlnst++) {
	InputInstArray[getlnst] = InstStorageBuf.readLine();
	//LinesCounter = LinesCounter+1;
	//if(InputInstArray[getlnst].equals("}"))
	if(InputInstArray[getlnst].isEmpty()) {
		break;
	}
}





我想你想要的是你想要读取的数据从命令行开始,当用户不想插入更多数据时,请停止循环。



最好的问候,

Filipe



What I''m supposing what do you want is that you want to read data from command line and when the user wants not insert more data, stop the loop.

Best Regards,
Filipe


这篇关于用Java读取多个命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆