日期:2014-05-19  浏览次数:20818 次

各位 给帮满看一下 为啥会报错 难道是我 写错了还是怎么的
import java.util.*;
import java.io.*;
package example;

public class HelloWorld {
public static void main(String[] args) {
PrintWriter out = new PrintWriter("D:\\htdocs\\myfile.txt");
System.out.print("what is your name ?");
String name = out.nextLine();
System.out.print("how old are you ?");
int age = out.nextInt();
System.out.println("hello" + name + "Next year,you `ll be" + (age + 1));

}

}


我想把 名字和年龄写进 D:\\htdocs\\myfile.txt 这个文件 请问我这个 程序 写错了吗 为啥 Eclipse 报错呢 


Exception in thread "main" java.lang.Error: Unresolved compilation problems
The method nextLine() is undefined for the type PrintWriter
The method nextInt() is undefined for the type PrintWriter

at example.HelloWorld.main(HelloWorld.java:9)


------解决方案--------------------
这个错误很简单,
The method nextLine() is undefined for the type PrintWriter 
The method nextInt() is undefined for the type PrintWriter 
好好读读这个错误信息
nextLine() 方法没被定义在PrintWriter类里

好好看看JDK的API文档吧!