0
点赞
收藏
分享

微信扫一扫

java 《十一》获取当前项目路径并且读取文件

灯火南山 2022-08-02 阅读 100


package com.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

import javax.servlet.http.HttpServletRequest;

import com.mysql.jdbc.log.LogFactory;

/**
* 读取本地文本文件
*
* @author yushen
*
*/
public class StringOrbdfile {
/**
*
* @param fullFileName
* @return
*/
public static String getBDJson(String fullFileName) {
File file = new File(fullFileName);
Scanner scanner = null;
StringBuilder buffer = new StringBuilder();
try {
scanner = new Scanner(file, "GBK");
while (scanner.hasNextLine()) {
buffer.append(scanner.nextLine());
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (scanner != null) {
scanner.close();
}
}
return buffer.toString();
}

/**
* ready Go
*
*/
public static void main(String[] args) {
// 获取当前项目路径
String path = System.getProperty("user.dir");

System.out.println(getBDJson(path + "/WebRoot/json/lol.json"));

}
}

 

举报

相关推荐

0 条评论