何らかの理由で、整数に変換するための文字列数値を取得できません。エラーが実行されます:
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];
}
行の分割は 6327818260 6486 SUB-TOTAL: E:\WIS26\LCORRES のようになります