如果我有一个包含以下字符串的文件 numbers.txt
:
*1222223* @4555556 !7888889! $19.99
我将如何读取该行,删除符号,并通过键盘模拟输出它,如下所示:
4555556 [TAB] 7888889 [TAB] [TAB] 1222223 [TAB] 19.99
[TAB] 是 TAB 键的模拟,而不是文字字符串。
当然,在输出过程中,我不知道这些数字是什么,甚至不知道这些数字最初的顺序是什么。将 *
@
!
和 $
符号视为这些数字位置的占位符,我想从 * @ 开始$
输入到 @ ! * $
输出。
如果这还不够具体,请告诉我。
编辑:我对Java一无所知。我负责批处理/shell 脚本、HTML、CSS 和一些 PHP。我的问题涉及我的公司需要在一个简单的程序中实施的一项操作,但我们缺乏 Java 专业知识。
If I had a file numbers.txt
with the following string:
*1222223* @4555556 !7888889! $19.99
How would I go about reading that line, removing the symbols, and outputting it via keyboard emulation as follows:
4555556 [TAB] 7888889 [TAB] [TAB] 1222223 [TAB] 19.99
[TAB] being emulation for the TAB key as opposed to a literal string.
Of course, during the output, I do not know what the numbers are, or even what order those numbers are in originally. Think of the *
@
!
and $
symbols as placeholders for the location of these numbers, and I want to go from a * @ ! $
input to a @ ! * $
output.
Let me know if this isn't specific enough.
EDIT: I know absolutely nothing about Java. I do batch/shell scripting, HTML, CSS and some PHP. My question pertains to an action that my company needs to implement into a simple program but we are ill equipped with Java-Know-How.
发布评论
评论(1)
如果我理解你,你正在寻找的是这样的东西
http://gruimed.blogspot.com/2009/09/using-java-robot-to-type-text-strings.html
编辑:逐字符读取文件,你可以使用这个:
http://www.java2s.com/Code /Java/File-Input-Output/Readfilecharacterbycharacter.htm
鉴于,在链接第一个链接与机器人示例中,有一个方法
将每个字符转换为键码并使用 java.awt.Robot 键入它。在键入逻辑中使用条件排除任何不必要的字符,并使用机器人中的仿真和 TAB 的键码插入制表符,该键码存储在 java.awt.event.KeyEvent.VK_TAB 常量中。
If i'm understanding you, what you are looking for is something like this
http://gruimed.blogspot.com/2009/09/using-java-robot-to-type-text-strings.html
Edit: to read a file character by character, you can use this:
http://www.java2s.com/Code/Java/File-Input-Output/Readfilecharacterbycharacter.htm
Given that, in the link first link with the robot example,there's a method
to translate each character into a keycode and type it using java.awt.Robot. Exclude any non-necessary characters using conditionals in the typing logic and insert tabs using emulation in the robot with TAB's keycode, which is stored in java.awt.event.KeyEvent.VK_TAB constant.