如何在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
最满意答案
假设您输入
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 ...
-
NumberFormatException的(NumberFormatException)[2023-11-12]
那是因为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 ...
-
缓冲读取器HTTP POST(Buffered Reader HTTP POST)[2022-08-15]
我同意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中删除所有不可打印字符的最快方法 如何 ...