English 中文(简体)
JRuby使用 Java系统。
原标题:JRuby to use Java system.console

对Jruby说新话,我需要对这一法典有所帮助。 我知道这样做是错误的。 我确实需要帮助如何获得这一权利。

What am I doing? Mask user password input in JRuby. Plan: Use java s System.console to do it.

法典:

require "rubygems"
require "java"

include_class  java.io.PrintStream 
include_class  java.io.ByteArrayOutputStream 
include_class  java.lang.System 
include_class  java.io.Console 



Console console = System.console();
String password = console.readPassword("Enter password: ");

puts password

请提供帮助。 谢谢。

问题回答

它需要从<代码>char[]退回到一个固定物体,例如:

require "java"

include_class  java.lang.System 
include_class  java.io.Console 

console = System.console();
password = console.readPassword("Enter password: ");

passwordString = java.lang.String.new(password)

printf("%s
", passwordString )

页: 1

require  java 
include_class  java.lang.System 
include_class  java.io.Console 

# Read the password into a char[]
java_char_array = System.console.readPassword("password:")

# Turn that into a java.lang.String
java_string = java.lang.String.new(java_char_array)

# Turn this into a Ruby string and strip off the newline.
password = java_string.to_s.strip

<密码>的原因 贴上<条码>()是一个比喻复杂的问题,但背后是大歌和舞蹈,涉及安全问题。 您可使用<条码>Array. 填满<>/code> 至_nuke the content of char[],从而将密码从长时间内停在记忆中。

Try this,

console = System.console();
String password = console.readPassword("Enter password: ");

puts password




相关问题
what do these ruby warnings mean?

cqq.rb:96 **warning: Statement not reached.** /root/newpackage/lib.rb:727 **warning: instance variable @object not initialized** Error: Your application used more memory than the safety cap of 500m. ...

How to register a JDBC driver using jruby-complete.jar?

I m trying to write a script that is executed with the jruby-complete.jar like so: java -cp derby.jar; -Djdbc.drivers=org.apache.derby.jdbc.EmbeddedDriver -jar jruby-complete.jar -S my_script.rb I m ...

How do I unmarshal a ruby object in java?

I have a an object that I d like to grab the contents of in java. The only problem is that is is currently in ruby. irb(main):050:0> blah => "...

What s the difference between Ruby and JRuby? [closed]

Can anyone please provide me in layman s terms the difference between developing a JRuby and a Ruby, Rails application? I use NetBeans as my Ruby on Rails IDE and every-time I create a project is ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

热门标签