出于某种原因,我无法将字符串数值转换为整数,我得到的错误是运行:
Exception in thread "main" java.lang.NumberFormatException: For input string: "6327818260"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:495)
at java.lang.Integer.parseInt(Integer.java:527)
at MyDirectory.getsize(MyDirectory.java:18)
at a19010.main(a19010.java:79)
Java 结果:1
如果我的输入字符串是“6327818260”为什么不能变成整数?我的代码是
public String getsize()
{
int intSize = Integer.parseInt(mySize);
int count = 0;
String dataType = "";
while (intSize > 1000)
{
intSize = intSize / 1000;
count++;
}
switch (count)
{
case 0:
dataType = "Bytes";
break;
case 1:
dataType = "KB";
break;
case 2:
dataType = "MB";
break;
case 3:
dataType = "GB";
break;
case 4:
dataType = "KB";
break;
}
return intSize + dataType ;
}
mySize 取自从此处的文本文件中获取的字符串的一部分
public class MyDirectory
{
String myName = "" ;
String myNum = "";
String mySize = "";
public MyDirectory(String line)
{
line = line.trim();
String[] lineParts = line.split(" ");
mySize = lineParts[0];
myNum = lineParts[1];
myName = lineParts[3];
}
im 拆分的行看起来像 6327818260 6486 SUB-TOTAL: E:\WIS26\LCORRES