在Java中通过控制台编辑给定的字符串 [英] Edit a given String over the Console in Java

查看:47
本文介绍了在Java中通过控制台编辑给定的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在Java中从用户键盘读取字符串的各种方法(扫描仪,控制台,BufferedReader),但是,似乎没有一种方法能够接受用户可以编辑的给定字符串.

I'm aware of various methods for reading a String from the user's keyboard in Java (Scanner, Console, BufferedReader), however, none of them seems to be capable to accept a given String that the user can edit.

要在代码中重新表述,我正在寻找这样的东西:

To rephrase it in code, I'm looking for something like this:

Scanner sc = new Scanner(System.in);
System.out.print("Please edit as you like: " + s);
s = sc.nextLine(s);

这似乎很简单,我是否忽略了某些内容?还是在没有GUI的Java中这真的不可能吗?

As this seems so simple, am I overlooking something? Or is this really not possible in Java without a GUI?

推荐答案

看起来不可能.有类似的帖子对此进行了讨论. Java:使用Scanner.nextLine()上的默认值填充Scanner.

Doesn't look like it will be possible. There are similar posts discussing this. Java: populating Scanner with default value on Scanner.nextLine();

其中讨论了一些选项,但即使提供这些选项的人也清楚地表明,它不满足规定的要求

A few options have been discussed in there but even the people providing those options are clear that it doesn't meet the stated requirment

这篇关于在Java中通过控制台编辑给定的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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