Probleme de conversion string --> int en java

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

1 réponse

  1. Modérateur
    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;
        }
    }