package com.gaden.Test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class ReadFile {
public static String readFile(String filePathAndName) {
String fileContent = "";
try {
File f = new File(filePathAndName);
if (f.isFile() && f.exists()) {
InputStreamReader read = new InputStreamReader(
new FileInputStream(f), "UTF-8");
BufferedReader reader = new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null) {
fileContent += line +"\r\n";
// //line = line.replaceAll("\r\n", "|#|");
// WriteFile.writeFile(outputPath, line);
System.out.println("go!!");
}
read.close();
}
} catch (Exception e) {
System.out.println("du wenjian cuo wu");
e.printStackTrace();
}
return fileContent;
}
public static List<String> readFileForList(String filePathAndName) {
List<String> fileContent = new ArrayList<String>();
try {
File f = new File(filePathAndName);
if (f.isFile() && f.exists()) {
InputStreamReader read = new InputStreamReader(
new FileInputStream(f), "UTF-8");
BufferedReader reader = new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null) {
fileContent.add(line);
}
read.close();
}
} catch (Exception e) {
System.out.println("xie wenjian cuowu ");
e.printStackTrace();
}
return fileContent;
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class ReadFile {
public static String readFile(String filePathAndName) {
String fileContent = "";
try {
File f = new File(filePathAndName);
if (f.isFile() && f.exists()) {
InputStreamReader read = new InputStreamReader(
new FileInputStream(f), "UTF-8");
BufferedReader reader = new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null) {
fileContent += line +"\r\n";
// //line = line.replaceAll("\r\n", "|#|");
// WriteFile.writeFile(outputPath, line);
System.out.println("go!!");
}
read.close();
}
} catch (Exception e) {
System.out.println("du wenjian cuo wu");
e.printStackTrace();
}
return fileContent;
}
public static List<String> readFileForList(String filePathAndName) {
List<String> fileContent = new ArrayList<String>();
try {
File f = new File(filePathAndName);
if (f.isFile() && f.exists()) {
InputStreamReader read = new InputStreamReader(
new FileInputStream(f), "UTF-8");
BufferedReader reader = new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null) {
fileContent.add(line);
}
read.close();
}
} catch (Exception e) {
System.out.println("xie wenjian cuowu ");
e.printStackTrace();
}
return fileContent;
}
public static void writeFile(String filePathAndName, String fileContent) {
try {
File f = new File(filePathAndName);
if (!f.exists()) {
f.createNewFile();
}
OutputStreamWriter write = new OutputStreamWriter(
new FileOutputStream(f,true), "UTF-8");
BufferedWriter writer = new BufferedWriter(write);
writer.write(fileContent);
// writer.newLine();
writer.flush();
writer.close();
} catch (Exception e) {
System.out.println("xie wen jian cuo wu");
e.printStackTrace();
}
}