This commit is contained in:
xiangwbs
2018-03-08 23:44:04 +08:00
parent b34592cb2a
commit cd8665810a
2 changed files with 5 additions and 12 deletions
@@ -4,6 +4,7 @@ import org.springframework.core.io.ClassPathResource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
* 说明: java.io.File File的每一个实例可以表示文件系统中的一个文件或目录 使用file可以:
@@ -62,7 +63,10 @@ public class FileDemo {
* java resources 编译后在WEB-INF/classes下 同级
*/
String tomcatHome = System.getProperty("catalina.home");//服务器tomcat路径
ClassPathResource pic = new ClassPathResource("conf");//获取classes下conf文件夹路径
ClassPathResource pic = new ClassPathResource("file");//获取classes下file文件夹路径
String absolutePath = pic.getFile().getAbsolutePath();
//配置文件
String filePath = IODemo.class.getResource("/redis.properties").getPath();
InputStream in = IODemo.class.getResourceAsStream("/redis.properties");
}
}
@@ -1,7 +1,5 @@
package com.xwbing.demo;
import org.springframework.core.io.ClassPathResource;
import java.io.*;
/**
@@ -96,14 +94,5 @@ public class IODemo {
PrintWriter pw1 = new PrintWriter(osw, true);///////当第一个参数为流,可以使用第二个参数来指定是否自动flush
pw1.println("......");
pw1.close();
/**
* 读取文件
*/
String filePath = IODemo.class.getResource("/redis.properties").getPath();
InputStream in = IODemo.class.getResourceAsStream("/redis.properties");
ClassPathResource pic = new ClassPathResource("file");
String absolutePath = pic.getFile().getAbsolutePath();
}
}