请教高手们一个很菜的问题 我先读入了一个文件FileReader in=new FileReader("c:/mydir.txt");这个文本里有很多文字我要怎样设计才能这样显示出这么文本来我输入一个"1"它显示一行文件里的文字这样一直到完全显示完 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class ReadFileLineByLine { public static final String FILENAME = "e:/1.txt"; public static void main(String[] args) throws Exception { BufferedReader reader = createBufferedReaderFromFile(FILENAME); try { printFileLineByLine(reader); } finally { reader.close(); } } private static BufferedReader createBufferedReaderFromFile(String filename) throws FileNotFoundException { return new BufferedReader(new FileReader(filename)); } private static void printFileLineByLine(BufferedReader reader) throws IOException { String line; while ((line = readOneLine(reader)) != null) { readAndPause(line); } printEndingMessage(); } private static void printEndingMessage() { System.out.println("\n文件输出完毕。"); } private static void readAndPause(String line) { printLine(line); readUserInput(); } private static void readUserInput() { Scanner scanner = new Scanner(System.in); String line = null; // 直到用户输入"1"回车才继续 while (!"1".equals(line)) { line = scanner.nextLine(); } } private static void printLine(String str) { System.out.println(str); } private static String readOneLine(BufferedReader reader) throws IOException { return reader.readLine(); }} public class Rt { public static void main(String[] args) throws IOException { try { boolean stop=true; while(stop){ BufferedReader br=new BufferedReader(new FileReader("F:\\test.txt")); Scanner s=new Scanner(System.in); int i=s.nextInt(); for(int j=0;j<i;j++) { System.out.println(br.readLine()); } } } catch (FileNotFoundException e) { e.printStackTrace(); } }}运行结果为:1你好2你好haha3你好haha我4你好haha我不dui\好了,楼主结贴吧 求给思路 新手关于接口的问题 [求助] java实现网络监控有可能吗?思路有什么? 谁能给我一个SQLserver2000中文企业版的下载地址!谢谢~~~~~ 求教几个菜鸟级的练习题 我做的2个网页连接不上是怎么回事啊!~请各位高手指点下!~ 什么地方有这个包 sun.misc.*; 大家好 我想学JAVA~ 能否访问? 有关TOMCAT,等待你的答复! 在Frame中添加了一个TextField,把它设置成了不可编辑模式,但是把鼠标点上去还是会有插入光标在那删,插入光标如何隐藏呢? 如何 让JTable的选择模式只能选择单元格
BufferedReader reader = createBufferedReaderFromFile(FILENAME); try {
printFileLineByLine(reader);
} finally {
reader.close();
}
} private static BufferedReader createBufferedReaderFromFile(String filename)
throws FileNotFoundException { return new BufferedReader(new FileReader(filename));
} private static void printFileLineByLine(BufferedReader reader) throws IOException {
String line; while ((line = readOneLine(reader)) != null) {
readAndPause(line);
} printEndingMessage();
} private static void printEndingMessage() {
System.out.println("\n文件输出完毕。");
} private static void readAndPause(String line) {
printLine(line);
readUserInput();
} private static void readUserInput() {
Scanner scanner = new Scanner(System.in);
String line = null; // 直到用户输入"1"回车才继续
while (!"1".equals(line)) {
line = scanner.nextLine();
}
} private static void printLine(String str) {
System.out.println(str);
} private static String readOneLine(BufferedReader reader) throws IOException {
return reader.readLine();
}
}
public class Rt {
public static void main(String[] args) throws IOException {
try {
boolean stop=true;
while(stop){
BufferedReader br=new BufferedReader(new FileReader("F:\\test.txt"));
Scanner s=new Scanner(System.in);
int i=s.nextInt();
for(int j=0;j<i;j++) {
System.out.println(br.readLine());
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}运行结果为:1
你好
2
你好
haha
3
你好
haha
我
4
你好
haha
我
不dui\
好了,楼主结贴吧