Could somebody help me to figure out how to solve a weird (for me) issue. The idea is we get a short String from file (to be precise string is "117_63_", where "_" are space symbols and the file itself is UTF-8 encoded) we split this string into integers "117" and "63" but when we conver them using Inetger.parseint() method it returns exception ...
java.lang.NumberFormatException: For input string: "117"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at xor_cipher.get_crypted_ints_from_string(xor_cipher.java:79)
at xor_cipher.decrypt(xor_cipher.java:49)
at the_main.main(the_main.java:25)
main :
///////////////////////////////////
// //
// Main entrance //
// //
///////////////////////////////////
public static void main( String[ ] cmd_arguments ) {
// Just for the testing
File fl = new File( "account_database" );
try
{
Scanner Get = new Scanner( fl );
String tmp = Get.nextLine( );
tmp = xor_cipher.decrypt( tmp );
Get.close( );
}
catch ( Exception EXC ) {
EXC.printStackTrace( );
System.exit( 1 );
}
}
function which invokes exception and is located in another class :
////////////////////////////////////
// //
// Convert string of integers //
// to array of integers ... //
// //
////////////////////////////////////
public static int[ ] get_crypted_ints_from_string( String crypted_ints_as_string ) {
int amount = 0;
for ( int i = 0; i < crypted_ints_as_string.length( ); i++ ) {
if ( crypted_ints_as_string.charAt( i ) == ' ' ) amount++;
else continue;
}
int array[ ] = new int[ amount ];
int analyzed_border = 0;
for ( int i = 0; i < array.length; i++ ) {
String tmp = new String( );
for ( int j = analyzed_border; j < crypted_ints_as_string.length( ); j++ ) {
if ( crypted_ints_as_string.charAt( j ) == ' ' ) {
array[ i ] = Integer.parseInt( tmp ); // <-- exception when tmp="112"
analyzed_border = j + 1;
break;
}
else if ( j == crypted_ints_as_string.length( ) - 1 ) {
tmp += crypted_ints_as_string.charAt( j );
array[ i ] = Integer.parseInt( tmp );
analyzed_border = j + 1;
break;
}
else tmp += crypted_ints_as_string.charAt( j );
}
}
return array;
}
I had been "fighting" that for a long time already, i would appreciate if anyone could at least give me a tip ..