-
-
-
import java.io.BufferedReader;
-
-
import java.io.FileInputStream;
-
import java.io.FileOutputStream;
-
import java.io.IOException;
-
import java.io.InputStreamReader;
-
import java.io.OutputStreamWriter;
-
-
-
-
-
-
-
-
-
-
public
class
FilePathDemo {
-
public
static
void
main
(String[] args)
throws IOException {
-
-
-
File srcFolder =
new File(
"文件路径");
-
-
-
getAllJavaFilePaths(srcFolder);
-
-
-
private
static
void
getAllJavaFilePaths
(File srcFolder)
throws IOException {
-
-
-
File[] fileArray = srcFolder.listFiles();
-
-
-
for (File file : fileArray) {
-
-
-
if (file.isDirectory()) {
-
-
getAllJavaFilePaths(file);
-
-
-
-
if (file.getName().endsWith(
".java")) {
-
-
-
FileInputStream fis =
new FileInputStream(file);
-
InputStreamReader isr =
new InputStreamReader(fis,
"GBK");
-
BufferedReader br =
new BufferedReader(isr);
-
-
-
-
StringBuffer sb =
new StringBuffer();
-
-
-
while ((str = br.readLine()) !=
null) {
-
-
-
-
-
String str2 = sb.toString();
-
-
-
FileOutputStream fos =
new FileOutputStream(file.getAbsolutePath(),
false);
-
OutputStreamWriter osw =
new OutputStreamWriter(fos,
"UTF-8");
-
-
-
-
-
-
-
-
-
-
-
-
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69982209/viewspace-2713640/
,如需转载,请注明出处,否则将追究法律责任。