【发布时间】:2015-04-15 02:50:41
【问题描述】:
package chapterreader;
import java.util.Scanner;
import java.io.File;
public class ChapterReader {
public static void main(String[] args) throws Exception {
Chapter myChapter = new Chapter();
File chapterFile = new File("toc.txt");
Scanner chapterScanner;
//check to see if the file exists to read the data
if (chapterFile.exists()) {
System.out.printf("%7Chapter %14Title %69Page %80Length");
chapterScanner = new Scanner(chapterFile);
//Set Delimiter as ';' & 'new line'
chapterScanner.useDelimiter(";|\r\n");
while (chapterScanner.hasNext()) {
//Reads all the data from file and set it to the object Chapter
myChapter.setChapterNumber(chapterScanner.nextInt());
myChapter.setChapterTitle(chapterScanner.next());
myChapter.setStartingPageNumber(chapterScanner.nextInt());
myChapter.setEndingPageNumber(chapterScanner.nextInt());
displayProduct(myChapter);
}
chapterScanner.close();
} else {
System.out.println("Missing Chapter File");
}
}
//Display the Chapter Information in a correct Format
public static void displayProduct(Chapter reportProduct) {
System.out.printf("%7d", reportProduct.getChapterNumber());
System.out.printf("%-60s", reportProduct.getChapterTitle());
System.out.printf("%-6d", reportProduct.getStartingPageNumber());
System.out.printf("%-7d%n", reportProduct.getEndingPageNumber());
}
}
然后我得到一个错误:
运行:线程“main”中的异常 java.util.UnknownFormatConversionException: Conversion = 'ti' at java.util.Formatter$FormatSpecifier.checkDateTime(Formatter.java:2915) 在 java.util.Formatter$FormatSpecifier.(Formatter.java:2678) 在 java.util.Formatter.parse(Formatter.java:2528) 在 java.util.Formatter.format(Formatter.java:2469) 在 java.io.PrintStream.format(PrintStream.java:970) 在 java.io.PrintStream.printf(PrintStream.java:871) 在 chapterreader.ChapterReader.main(ChapterReader.java:17) Java 结果:1 构建成功(总时间:0 秒)
这个错误有什么问题?请帮忙!
【问题讨论】:
标签: java multithreading exception