再一次,我做Java的图形(Graphics2D的),但我注意到,没有Polygon.Double或Polygon.Float类,而有Rectangle2D.Float和Rectangle2D.Double类.
有人知道为什么吗?我只需要使用双精度作为点绘制三角形.
我正在尝试使用java.util.Scanner逐个字符地读取单行文件.但是我得到了这个例外":
Exception in thread "main" java.util.InputMismatchException: For input string: "contents of my file"
at java.util.Scanner.nextByte(Scanner.java:1861)
at java.util.Scanner.nextByte(Scanner.java:1814)
at p008.main(p008.java:18) <-- line where I do scanner.nextByte()
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
public static void main(String[] args) throws FileNotFoundException {
File source = new File("file.txt");
Scanner scanner = new Scanner(source);
while(scanner.hasNext()) {
System.out.println((char)scanner.nextByte());
}
scanner.close()
}
Run Code Online (Sandbox Code Playgroud)
有没有人对我可能做错了什么有任何想法?
编辑:我意识到我写了hasNext()而不是hasNextByte().但是,如果我这样做,它不打印任何东西.
我的Java类组织变得有点乱,所以我正在讨论我在Java学习中跳过的东西:类路径.我无法安静地得到心爱的类来编译我为他们创建的包.这是我的文件夹层次结构:
.
com/
david/
Greet.java
greeter/
SayHello.java
SayGoodbye.java
Run Code Online (Sandbox Code Playgroud)
SayHello的构造函数只打印"hello"和SayGoodbye的打印"Goodbye",而Greet的main方法只创建了这两个对象.在SayHello的顶部是包com.david.greeter; 与SayGoodbye和Greet相同的是包com.david;
在greeter文件夹中,我能够编译两个java文件但是如果我转到当前目录(保存com的目录)并执行javac -cp"com.david.greeter.*"com/david/Greet.java它说它找不到类以及说包com.david.greeter不存在.我也试过手动设置$ CLASSPATH.
我在这里结束了,Stackoverflow(正如我在这里发布的那样).你们中的任何人都知道我做错了什么吗?