Skip to content

Commit 74b1b09

Browse files
FileUtils读取文件及测试类
1 parent 0f5be6e commit 74b1b09

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-1
lines changed

.idea/libraries/Maven__commons_io_commons_io_2_4.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Utils.iml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3-
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />
66
<content url="file://$MODULE_DIR$">
@@ -15,6 +15,7 @@
1515
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
1616
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
1717
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
18+
<orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
1819
<orderEntry type="library" name="Maven: com.google.guava:guava:23.6-jre" level="project" />
1920
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
2021
<orderEntry type="library" name="Maven: org.checkerframework:checker-compat-qual:2.0.0" level="project" />

logs/ssm.log

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
[INFO] [2018-02-02 17:22:36][com.PropertyUtil]开始加载properties文件内容.......
88
[INFO] [2018-02-02 17:22:36][com.PropertyUtil]加载properties文件内容完成...........
99
[INFO] [2018-02-02 17:22:36][com.PropertyUtil]properties文件内容:{url=jdbc:mysql://localhost/spring, maxIdle=20, maxActive=20, maxWait=60000, username=root, minIdle=1, password=root, initialSize=0, driver=com.mysql.jdbc.Driver}
10+
[INFO] [2018-02-06 11:27:54][com.PropertyUtil]开始加载properties文件内容.......
11+
[INFO] [2018-02-06 11:27:54][com.PropertyUtil]加载properties文件内容完成...........
12+
[INFO] [2018-02-06 11:27:54][com.PropertyUtil]properties文件内容:{url=jdbc:mysql://localhost/spring, maxIdle=20, maxActive=20, maxWait=60000, username=root, minIdle=1, password=root, initialSize=0, driver=com.mysql.jdbc.Driver}
1013

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
<version>3.7</version>
3636
</dependency>
3737

38+
<dependency>
39+
<groupId>commons-io</groupId>
40+
<artifactId>commons-io</artifactId>
41+
<version>2.4</version>
42+
</dependency>
43+
3844
<dependency>
3945
<groupId>com.google.guava</groupId>
4046
<artifactId>guava</artifactId>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com;
2+
3+
import org.apache.commons.io.FileUtils;
4+
5+
import java.io.File;
6+
import java.io.IOException;
7+
import java.util.List;
8+
9+
/**
10+
* Created by lenovo on 二月
11+
*/
12+
public class FileUtilsDemo {
13+
public static void readFile(String fileName,String encoding ) throws IOException {
14+
String str=FileUtils.readFileToString(new File(fileName),encoding);
15+
System.out.println(str);
16+
}
17+
18+
public static void readFileByLine(String fileName,String encoding) throws IOException {
19+
List<String> list=FileUtils.readLines(new File(fileName), encoding);
20+
for(String str:list) {
21+
System.out.println(str);
22+
}
23+
}
24+
25+
public static void writeFile(String fileName, CharSequence data, String encoding) throws IOException {
26+
FileUtils.write(new File(fileName),data,encoding,true);
27+
}
28+
}

0 commit comments

Comments
 (0)