Probleme de conversion string --> int en java

Fermé
bloomingdals - 28 mars 2013 à 16:48
KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 - 28 mars 2013 à 18:50
Bonjour,

je n'arrête pas d'essayer de convertir une chaine de caractères en entier mais ca me retourne une exception voici mon code

public int taille(File file) throws IOException
{
Shell sh = new Shell();
File dir= new File("/root/Desktop/");
sh.setDirectory(dir);
String cmd="sed -n '$=' "+file+"";
String t=sh.command(cmd).consumeAsString();

int taille=Integer.parseInt(t);
return (taille);
}

voici le message d'erreur
Exception in thread "main" java.lang.NumberFormatException: For input string: "89"

pouriez vous m'aider svp
merci
A voir également:

1 réponse

KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
28 mars 2013 à 18:50
Modifies la fin de ta méthode comme ceci, ça t'en apprendra peut-être un peu plus :

    ...
    
    try
    {
        int taille=Integer.parseInt(t); 
        return taille;
    }
    catch (NumberFormatException e)
    {
        System.err.println(Arrays.toString(t.getBytes()));
        throw e;
    }
}
0