java中如何通过file程序去读取查询文件中的文件

2025-02-24 18:40:46
推荐回答(3个)
回答1:

File类有两个常用方法可以得到文件路径一个是:getCanonicalPath(),另一个是:getAbsolutePath(),可以通过File类的实例调用这两个方法例如file.getAbsolutePath()其中file是File的实例对象。下面是一个具体例子: public class PathTest{ publ...

回答2:

分为读字节,读字符两种读法 ◎◎◎FileInputStream 字节输入流读文件◎◎◎ public class Maintest { public static void main(String[] args) throws IOException { File f=new File("G:\\just for fun\\xiangwei.txt"); FileInputStream fin=new Fi...

回答3:

/** * 读取配置文件 */private Properties loadProperty() {Properties prop=new Properties();try {//FileInputStream is=new FileInputStream("config.properties");InputStream is=this.getClass().getResourceAsStream("/config.properties"...