首页 \ 问答 \ 如何在node.js中设置一个环境变量?(How can I set an environmental variable in node.js?)

如何在node.js中设置一个环境变量?(How can I set an environmental variable in node.js?)

如何在node.js中设置一个环境变量?

我宁可不依赖任何特定的平台,比如运行export或者cmd.exe的设置。


How can I set an environmental variable in node.js?

I would prefer not to rely on anything platform specific, such as running export or cmd.exe's set.


原文:https://stackoverflow.com/questions/10829433
更新时间:2023-09-24 14:09

最满意答案

假设您输入a<Enter>

您的缓冲读取器读取a字符:

char ch =(char)buf.read();

然后它读取行的结尾:

buf.readLine()

该行的结尾是一个空字符串。 因此,错误消息(你应该仔细阅读 ,因为它告诉你你想要解析为一个整数,从而解释了这个问题):

java.lang.NumberFormatException:用于输入字符串:“”


Solved it!!It's not a way u can use all the time but it can be used in simpler n shorter programs. Just accept the other values first then accept the char value(accept char in the end--after accepting all values of all other data types). The following is the code to accept a character to accept a character using BufferedReader:

    System.out.println("Enter the Character");
    char ch =(char)buf.read();

相关问答

更多
  • Float.valueOf(String s)无法解析输入,则会抛出NumberFormatException 。 除了IOException之外,还要捕获一个。 在您的代码中,抛出NumberFormatException (如果输入无效)但未在方法内捕获,因此该方法将在完成finally块后立即返回。 Float.valueOf(String s) will throw a NumberFormatException if it can't parse the input. Catch that one ...
  • 假设您输入a 您的缓冲读取器读取a字符: char ch =(char)buf.read(); 然后它读取行的结尾: buf.readLine() 该行的结尾是一个空字符串。 因此,错误消息(你应该仔细阅读 ,因为它告诉你你想要解析为一个整数,从而解释了这个问题): java.lang.NumberFormatException:用于输入字符串:“” Solved it!!It's not a way u can use all the time but it can be used in ...
  • for是惰性的,只返回最终将从文件中读取数据的序列的头部。 当您的repl 打印for的内容时,该文件已经关闭 。 你可以修复这个pu包裹在一个doall (with-open [rdr (reader "path/to/file")] (doall (for [line (line-seq rdr)] line))) 虽然这会使序列失效。 这是我的misc.clj中的一个函数的示例,它在结束时懒洋洋地关闭文件: (defn byte-seq [rdr] "create ...
  • 在Python 2中,您希望避免使用TextIOWrapper对象,因为csv.reader()对象需要一个csv.reader() 。 它无法处理TextIOWrapper提供的unicode对象。 提供IOBase实现非常简单: class IOCompatibleKey(object): def __init__(self, s3_key): self.s3_key = s3_key def readable(self): return Tru ...
  • 那是因为6768886877对于一个int来说太大了。 使用long而不是。 long checkNumber = 0l; try{ checkNumber = Long.parseLong (phoneNumber); } catch (NumberFormatException e) { e.printStackTrace(); } That's because 6768886877 is too big of a number for an int. Use a long instead. ...
  • 你这样做是通过递归调用run()函数,检查是否可以读取更多行 - 这是一个示例 // Reload the file when you reach the end (i.e. when you can't read anymore strings) if ((sCurrentLine = br.readLine()) == null) { run(); } you do this by calling the run() function recursively, after checki ...
  • 我同意Hans的观点,你应该使用一个标准的,经过充分测试的库来做到这一点。 但是,如果您正在编写服务器以了解HTTP,请参阅您想做的事情。 你真的不能使用BufferedReader,因为它会缓冲输入并可能从套接字读取太多字节。 这就是为什么你的代码挂起,BufferedReader试图读取比在套接字上可用的字节更多的字节(因为POST数据没有行结束),并且它正在等待更多字节(这将永远不可用) 。 简单地解析POST请求的过程是直接使用InputStream 对于标题中的每一行,一次读取一个字节,直到获得' ...
  • 使用Scanner会容易得多,您可以在其中设置分隔符: Scanner scan = new Scanner(new File("/path/to/file.txt")); scan.useDelimiter(Pattern.compile(";")); while (scan.hasNext()) { String logicalLine = scan.next(); // rest of your logic } It would be much easier to do with a ...
  • 使用包装在BufferedInputStream的DataInputStream和readInt()方法。 这当然假设网络字节顺序是整数。 忘记所有这些arraycopy()东西。 Use a DataInputStream wrapped around a BufferedInputStream, and the readInt() method. This assumes network byte order in the integers of course. Forget all this arra ...
  • 我认为那是因为你的字符串中有不可打印的字符。 所有不可打印的字符都是< '0' 。 你可以在这里看到哪些是可打印的,哪些不是: http://web.itu.edu.tr/sgunduz/courses/mikroisl/ascii.html 这就是你无法在输出中看到引发异常的字符的原因。 如果您不想为这些情况抛出异常,则必须更准确地进行比较,例如在if语句中检查这些字符或使用正则表达式。 无论如何,SO中有几个问题可以替换这些字符,如下所示: 从Java String中删除所有不可打印字符的最快方法 如何 ...

相关文章

更多

最新问答

更多
  • 如何检索Ember.js模型的所有属性(How to retrieve all properties of an Ember.js model)
  • maven中snapshot快照库和release发布库的区别和作用
  • arraylist中的搜索元素(Search element in arraylist)
  • 从mysli_fetch_array中获取选定的值并输出(Get selected value from mysli_fetch_array and output)
  • Windows Phone上的可用共享扩展(Available Share Extensions on Windows Phone)
  • 如何在命令提示符下将日期设置为文件名(How to set file name as date in command prompt)
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • 从iframe访问父页面的id元素(accessing id element of parent page from iframe)
  • linux的常用命令干什么用的
  • Feign Client + Eureka POST请求正文(Feign Client + Eureka POST request body)
  • 怎么删除禁用RHEL/CentOS 7上不需要的服务
  • 为什么Gradle运行测试两次?(Why does Gradle run tests twice?)
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在android中的活动之间切换?(Switching between activities in android?)
  • Perforce:如何从Depot到Workspace丢失文件?(Perforce: how to get missing file from Depot to Workspace?)
  • Webform页面避免运行服务器(Webform page avoiding runat server)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 内存布局破解(memory layout hack)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • 我们可以有一个调度程序,你可以异步添加东西,但会同步按顺序执行吗?(Can we have a dispatcher that you can add things todo asynchronously but will be executed in that order synchronously?)
  • “FROM a,b”和“FROM a FULL OUTER JOIN b”之间有什么区别?(What is the difference between “FROM a, b” and “FROM a FULL OUTER JOIN b”?)
  • Java中的不可变类(Immutable class in Java)
  • bat批处理文件结果导出到txt
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • 德州新起点计算机培训学校主要课程有什么?
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • “latin1_german1_ci”整理来自哪里?(Where is “latin1_german1_ci” collation coming from?)