Vous cherchez de l'aide avec le code suivant:sortie d'un fichier dans printf
package pkgPeople;
import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class RetrieveNonSerializedFile {
public static void main(String[] args) throws Exception{
File inFile = new File("F:/CS9.27/friends2.dat");
Scanner reader = new Scanner(inFile);
while (reader.hasNextLine()){
String nm = reader.nextLine();
int height = reader.nextInt();
int weight = reader.nextInt();
double balance = reader.nextDouble();
long acctID = reader.nextInt();
System.out.println(nm + ":" + height + " inches " + weight + " pounds" + acctID + " account ID" + balance + "dollars");
/*writer.println(nm);
writer.println(height);
writer.println(weight);
writer.println(acctID);
writer.println(balance);*/
}
reader.close();
//writer.close();
}
}
Lors de l'exécution du programme, l'exception
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at pkgPeople.RetrieveNonSerializedFile.main(RetrieveNonSerializedFile.java:22)
est jeté.
Le friends2.dat est un fichier de données qui a les suivantes .....
Jim is the name of the person.
13 inches is the height of Jim.
14 pounds is the weight of Jim
1234.650000 dollars is the balance of Jim
12345 is the ID of the bank account.
Il est juste un fichier texte. Toute aide pour passer à travers le InputMismatch serait géniale. Merci.
Est-ce que Jim est sur sa propre ligne? Pourriez-vous joindre un exemple de fichier avec 2-3 enregistrements? –
oui c'est ligne par ligne. 5 lignes .. –