Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Float.intBitsToFloat抛出java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)_Java - Fatal编程技术网

Float.intBitsToFloat抛出java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)

Float.intBitsToFloat抛出java.lang.NumberFormatException.forInputString(NumberFormatException.java:68),java,Java,我试图把这个字符串10909116变成一个浮点数。当使用Float.intBitsToFloat时,我得到一个NumberFormatException。我试图通过将其设置为整数来解决此问题,但出现了以下错误: at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68) at java.base/java.lang.Integer.parseInt(Integer.java:

我试图把这个字符串10909116变成一个浮点数。当使用Float.intBitsToFloat时,我得到一个NumberFormatException。我试图通过将其设置为整数来解决此问题,但出现了以下错误:

at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
at java.base/java.lang.Integer.parseInt(Integer.java:658)
at java.base/java.lang.Integer.valueOf(Integer.java:963)
at Main.main(Main.java:32)
这是以下代码:


String file = Files.readString(Path.of(dir));

String[] pos = file.split("[ \n]");

for(int i = 0; i < pos.length; i++) {
temp = "" + Float.intBitsToFloat(Integer.valueOf(pos[i], 10));
pos[i] = temp;
}


String file=Files.readString(Path.of(dir));
字符串[]pos=file.split([\n]”);
对于(int i=0;i
代码没有问题。 问题是该文件包含方法无法转换为int的垃圾。 您可以删除所有不需要的数字

pos[i]=pos[i].replaceAll("[^0-9]", "");

堆栈跟踪则相反
Integer.valueOf
导致错误,而不是
Float.intBitsToFloat
pos[I]
似乎不包含正确格式的整数字符串。