用java语言怎样写一段程序读d盘的text.txt文件?
展开全部
/*Node.java*/
import java.io.File;
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.IOException;
public class Node{
public static void main(String args[]){
File file = new File("D:\\text.txt");
try{
Scanner scanner = new Scanner(new FileInputStream(file),"gbk");
while(scanner.hasNextLine(){
System.out.println(scanner.nextLine());
}
scanner.close();
}catch(IOException e){
scanner.close();
System.out.println("exception");
}
}
}
javac编译
java运行即可
import java.io.File;
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.IOException;
public class Node{
public static void main(String args[]){
File file = new File("D:\\text.txt");
try{
Scanner scanner = new Scanner(new FileInputStream(file),"gbk");
while(scanner.hasNextLine(){
System.out.println(scanner.nextLine());
}
scanner.close();
}catch(IOException e){
scanner.close();
System.out.println("exception");
}
}
}
javac编译
java运行即可
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询