从txt文件中读取ints并存储到数组中(Reading ints from a txt file and storing to an array)
我正在尝试从文本文件中读取整数并将它们存储到数组中。 该文本文件显示如下:
4 -9 -5 4 8 25 10 0 -1 4 3 -2 -1 10 8 5 8
然而,当我运行我的代码时,我在控制台窗口中获得了
[I@41616dd6
...public static void main(String[] args) throws IOException { FileReader file = new FileReader("Integers.txt"); int[] integers = new int [100]; int i=0; try { Scanner input = new Scanner(file); while(input.hasNext()) { integers[i] = input.nextInt(); i++; } input.close(); } catch(Exception e) { e.printStackTrace(); } System.out.println(integers); }
I am trying to read integers from a text file and store them into an array. The text file reads:
4 -9 -5 4 8 25 10 0 -1 4 3 -2 -1 10 8 5 8
Yet when I run my code I get
[I@41616dd6
in the console window...public static void main(String[] args) throws IOException { FileReader file = new FileReader("Integers.txt"); int[] integers = new int [100]; int i=0; try { Scanner input = new Scanner(file); while(input.hasNext()) { integers[i] = input.nextInt(); i++; } input.close(); } catch(Exception e) { e.printStackTrace(); } System.out.println(integers); }
原文:https://stackoverflow.com/questions/13716830
最满意答案
将提示提示给您期望的内容,如...提示。 这是paramiko交互示例。 请注意第21行和第37行 -
PROMPT = 'vagrant@paramiko-expect-dev:~\$\s+' interact.expect(PROMPT)
所以,当我将部分代码更新为:
interact = SSHClientInteraction(client, timeout=10, display=True) interact.expect(PROMPT) interact.send("ls") interact.expect(".*Maildir.*") file.write(interact.current_output_clean) client.close()
我有
testlog.txt
填充主目录的列表,远程主机。作为一个方面说明 - 切换到python 3.如果你开始,最好使用不知名的工具很快就会过时。 你也可以使用ipython,或者jupyter--代码更具交互性,测试速度更快。 也许netmiko会对你感兴趣?
Put prompt to something you expect, as... prompt. Here is paramiko interaction example. Please note lines 21, and 37 -
PROMPT = 'vagrant@paramiko-expect-dev:~\$\s+' interact.expect(PROMPT)
So, when I've updated part of your code to:
interact = SSHClientInteraction(client, timeout=10, display=True) interact.expect(PROMPT) interact.send("ls") interact.expect(".*Maildir.*") file.write(interact.current_output_clean) client.close()
I have
testlog.txt
filled with listing of the home directory, of remote host.As a side note - switch to python 3. If you are starting, it is better to use tool that is not well known to be outdated soon. Also you can use ipython, or jupyter - code will be more interactive, faster to test. Maybe netmiko will be interested for you?
相关问答
更多-
linux expect问题[2023-01-15]
#!/usr/bin/expect set timeout 10 set host_ip [lindex $argv 0] set password [lindex $argv 1] spawn ssh ${host_ip} expect { "(yes/no)?" { send "yes\n" expect "*assword:" { send "$password\n"} } "*assword:" { send "$password\n" } timeout {exit 1} # 3: 这里超时就会返 ... -
量角器等待超时(Protractor wait timing out)[2021-08-17]
可能是模态始终存在,但它的可见性是否被切换? 然后,我怀疑你应该检查元素是否可见而不是存在 : expect(modal.isDisplayed()).toBeTruthy(); 另请参见如何使用量角器检查元素是否可见? 。 然后,您可以使用@alecxe建议的预期条件,使用ExpectedConditions.visibilityOf 。 我也觉得有点怀疑click()承诺后面没有。 以下工作如何? element(by.css(merchantInfoClose)).click().then(func ... -
我是paramiko-expect的作者。 我刚刚在我的模块的0.2中实现了一个新功能,它允许你指定回调尾部方法,以便你可以随意处理当前行。 您可以使用它来grep输出或在显示之前进一步处理它。 预计回调函数将在完成操作当前行后返回要发送到sys.stdout.write的字符串。 这是一个例子: import traceback import paramiko from paramikoe import SSHClientInteraction def process_tail(line_prefix ...
-
试试这个(只修改:“.timeout(5000)”被添加到“it”)。 这对我有用。 基本上你必须改变异步呼叫的默认超时时间2秒 - 如果你期望你的异步呼叫将花费2秒以上。 describe('A promise', () => { it('should not timeout', () => { return new Promise((resolve, reject) => { setTimeout(() => { resol ...
-
不幸的是,你在WPF中创建了一个死锁。 在同步调用Stop时阻止UI线程。 服务器进程Stop请求并在返回客户端之前处理所有回调。 从服务器回调是同步处理的,因此阻止从Stop返回,直到WPF中的回调处理程序处理StatusUpdate回调。 但是StatusUpdate处理程序无法启动,因为它需要UI线程 - 并且UI线程仍在等待原始请求Stop完成。 如果您使用的是.NET 4.5,则解决方案很简单。 您将“click”处理程序标记为async并在客户端中调用await client.StopAsync ...
-
您可以自己阅读( expect_user )用户的密码,然后send其send到spawn'ed程序。 例如: [STEP 101] # cat foo.exp proc expect_prompt {} \ { global spawn_id expect -re {bash-[.0-9]+(#|\$)} } spawn ssh -t 127.0.0.1 bash --noprofile --norc expect "password: " stty -echo expect_user ...
-
帕拉米科和“远程蟒蛇”(Paramiko and “remote python”)[2023-08-20]
除非这是一个学术练习,或者你有一些特定的要求使用ssh,看看有点咄咄逼人 。 我从来没有使用它,但似乎成熟了。 Unless this is an academic exercise, or you have some specific requirement to use ssh, have a look at pushy. I've never used it but it seems mature. -
如评论中所示,性能计时插件使用s.performanceTiming(); 触发实际的插件。 这就是说它应该如何配置才能正常工作。 s.pte是用于确定是否执行实际插件的调用。 `s.pte = 'event10,event11,event12,event13,event14,event15,event16,event17,event18,event19' //[--------------------------- 1 to 8 ---------------------------][-- 9 --][ ...
-
帕拉米科期待超时(paramiko expect timing out)[2023-07-06]
将提示提示给您期望的内容,如...提示。 这是paramiko交互示例。 请注意第21行和第37行 - PROMPT = 'vagrant@paramiko-expect-dev:~\$\s+' interact.expect(PROMPT) 所以,当我将部分代码更新为: interact = SSHClientInteraction(client, timeout=10, display=True) interact.expect(PROMPT) interact.send("ls") intera ... -
帕拉米科 - 期待超时(paramiko-expect timing out)[2024-02-05]
如前所述,您必须定义您期望的提示,但也要注意它被读作正则表达式; 因此,必须转义特殊字符(如'$')。 我通常按如下方式设置提示: prompt = '.*\$\s+' sudo_prompt = '\[sudo\] password .*:\s+' root_prompt = '.*\#\s+' As already mentioned, you must define the prompt you are expecting, but also note that it's read as a reg ...