|
|
package main.java.com;
|
|
|
package com.xkl;
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
...
|
...
|
@@ -23,7 +23,7 @@ public class FileUtil { |
|
|
* @param filePath
|
|
|
*/
|
|
|
public static Set<String> readTxtFile(String filePath) {
|
|
|
Set<String> resSet = new HashSet<>();
|
|
|
Set<String> resSet = new HashSet<String>();
|
|
|
try {
|
|
|
String encoding = "GBK";
|
|
|
File file = new File(filePath);
|
...
|
...
|
@@ -44,16 +44,39 @@ public class FileUtil { |
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return resSet;
|
|
|
}
|
|
|
|
|
|
public static String readLine(String filePath) {
|
|
|
Set<String> resSet = new HashSet<String>();
|
|
|
try {
|
|
|
String encoding = "GBK";
|
|
|
File file = new File(filePath);
|
|
|
if (file.isFile() && file.exists()) { //判断文件是否存在
|
|
|
InputStreamReader read = new InputStreamReader(
|
|
|
new FileInputStream(file), encoding);//考虑到编码格式
|
|
|
BufferedReader bufferedReader = new BufferedReader(read);
|
|
|
String lineTxt = null;
|
|
|
while ((lineTxt = bufferedReader.readLine()) != null) {
|
|
|
if (!lineTxt.trim().toLowerCase().equals("")) {
|
|
|
return lineTxt.trim();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
read.close();
|
|
|
} else {
|
|
|
System.out.println("找不到指定的文件");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
System.out.println("读取文件内容出错");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
public static void main(String argv[]) {
|
|
|
String filePath = "C:\\Users\\zhaoyue\\Desktop\\ids";
|
|
|
// "res/";
|
|
|
Set<String> resSet = readTxtFile(filePath);
|
|
|
for (String line : resSet) {
|
|
|
System.out.println(line);
|
|
|
}
|
|
|
System.out.println(readLine(filePath));
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
|