最近用Java开发了一些项目,真心感觉Java的文件流真的没有C#.NET好用(说实话,我觉得Java就是没有C#好用)。所以,我用Java模仿了一下.NET里面的File类。
先放一下.jar包的链接https://download.csdn.net/download/newtypeofc/85506712
然后放一下源代码
目录
My_File_Controller接口
My_File_Controller_Class类
定义全局变量和构造函数
初始化窗口InitializeAllPath
AppendAllLines方法
AppendAllText方法
WriteAllText方法
ReadAllText方法
ReadAllBytes方法
WriteAllBytes方法
Create方法
Copy方法
Delete方法
Exists方法
Move方法
ReadAllLines方法
WriteAllLines方法
My_File_Controller接口
package My_File_Controller;
public interface My_File_Controller {
public abstract String[] ReadAllLines(String path);
public abstract void AppendAllLines(String path, String[] Text);
public abstract void WriteAllLines(String path,String[] Text);
public abstract String ReadAllText(String path);
public abstract void AppendAllText(String path, String Text);
public abstract void WriteAllText(String path, String Text);
public abstract byte[] ReadAllBytes (String path);
public abstract void WriteAllBytes(String path, byte[] Text);
public abstract void Copy(String path1, String path2);
public abstract void Create(String path);
public abstract void Delete(String path);
public abstract boolean Exists(String path);
public abstract void Move(String path1, String path2);
}
My_File_Controller_Class类
定义全局变量和构造函数
package My_File_Controller;
import java.io.BufferedReader;
public class My_File_Controller_Class implements My_File_Controller {
private String thisLine = new String();
private FileWriter fileWriter = null;
private FileReader fileReader = null;
private BufferedReader bufferedReader = null;
private BufferedWriter bufferedWriter = null;
private FileInputStream fileInputStream = null;
private FileOutputStream fileOutputStream = null;
private DataInputStream dataInputStream = null;
private File file = null;
public My_File_Controller_Class() {
InitializeAllPath();
}
初始化窗口InitializeAllPath
public void InitializeAllPath() {
thisLine = new String();
fileWriter = null;
fileReader = null;
bufferedReader = null;
bufferedWriter = null;
fileInputStream = null;
fileOutputStream = null;
dataInputStream = null;
file = null;
}
AppendAllLines方法
public void AppendAllLines(String path, String[] Text) {
try {
fileWriter = new FileWriter(path);
bufferedWriter = new BufferedWriter(fileWriter);
String thisLine = new String();
for(int i = 0;i < Text.length;i++) {
thisLine = Text[i];
bufferedWriter.write(thisLine + "rn");
}
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
AppendAllText方法
public void AppendAllText(String path, String Text) {
try {
//1.读取现有文件
String Text_now = ReadAllText(path);
//2.写入现有内容和新内容
fileWriter = new FileWriter(path);
bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(Text_now + Text);
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
WriteAllText方法
public void WriteAllText(String path, String Text) {
try {
fileWriter = new FileWriter(path);
bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(Text);
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
ReadAllText方法
public String ReadAllText(String path) {
String result = new String();
try {
System.out.println(path);
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while((thisLine = bufferedReader.readLine()) != null) {
result += thisLine;
}
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
return result;
}
ReadAllBytes方法
public byte[] ReadAllBytes (String path) {
byte[] result = new byte[100];
try {
fileInputStream = new FileInputStream(path);
//dataInputStream = new DataInputStream(fileInputStream);
fileInputStream.read(result,0,result.length);
fileInputStream.close();
}
catch(Exception ex) {
}
return result;
}
WriteAllBytes方法
public void WriteAllBytes(String path, byte[] Text) {
try {
fileOutputStream = new FileOutputStream(path);
fileOutputStream.write(Text);
fileOutputStream.flush();
fileOutputStream.close();
}
catch(Exception ex) {
}
}
Create方法
public void Create(String path) {
try {
file = new File(path);
file.createNewFile();
file = null;
}
catch(Exception ex) {
}
}
Copy方法
public void Copy(String path1, String path2) {
try {
byte[] text = ReadAllBytes(path1);
//创建新文件
Create(path2);
//开始写入
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
Delete方法
public void Delete(String path) {
try {
file = new File(path);
file.delete();
file = null;
}
catch(Exception ex) {
}
}
Exists方法
public boolean Exists(String path) {
file = new File(path);
boolean result = file.exists();
file = null;
return result;
}
Move方法
public void Move(String path1, String path2) {
try {
//1.读取并删除旧文件
byte[] text = ReadAllBytes(path1);
Delete(path1);
//2.创建新文件
Create(path2);
//3.写入新文件
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
ReadAllLines方法
public String[] ReadAllLines(String path) {
file = new File(path);
String[] result = new String[(int)file.length()];
int i = 0;
try {
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while( (thisLine = bufferedReader.readLine()) != null ) {
result[i] = thisLine;
i++;
}
bufferedReader.close();
}
catch(Exception ex) {
}
return result;
}
WriteAllLines方法
public void WriteAllLines(String path,String[] Text) {
try {
System.out.println(Text);
fileWriter = new FileWriter(path);
System.out.println(path);
bufferedWriter = new BufferedWriter(fileWriter);
for(int i = 0;i < Text.length;i++) {
bufferedWriter.write(Text[i] + "rn");
System.out.println(Text[i].toString());
}
bufferedWriter.flush();
fileWriter.close();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
定义全局变量和构造函数
package My_File_Controller;
import java.io.BufferedReader;
public class My_File_Controller_Class implements My_File_Controller {
private String thisLine = new String();
private FileWriter fileWriter = null;
private FileReader fileReader = null;
private BufferedReader bufferedReader = null;
private BufferedWriter bufferedWriter = null;
private FileInputStream fileInputStream = null;
private FileOutputStream fileOutputStream = null;
private DataInputStream dataInputStream = null;
private File file = null;
public My_File_Controller_Class() {
InitializeAllPath();
}
初始化窗口InitializeAllPath
public void InitializeAllPath() {
thisLine = new String();
fileWriter = null;
fileReader = null;
bufferedReader = null;
bufferedWriter = null;
fileInputStream = null;
fileOutputStream = null;
dataInputStream = null;
file = null;
}
AppendAllLines方法
public void AppendAllLines(String path, String[] Text) {
try {
fileWriter = new FileWriter(path);
bufferedWriter = new BufferedWriter(fileWriter);
String thisLine = new String();
for(int i = 0;i < Text.length;i++) {
thisLine = Text[i];
bufferedWriter.write(thisLine + "rn");
}
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
AppendAllText方法
public void AppendAllText(String path, String Text) {
try {
//1.读取现有文件
String Text_now = ReadAllText(path);
//2.写入现有内容和新内容
fileWriter = new FileWriter(path);
bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(Text_now + Text);
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
WriteAllText方法
public void WriteAllText(String path, String Text) {
try {
fileWriter = new FileWriter(path);
bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(Text);
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
ReadAllText方法
public String ReadAllText(String path) {
String result = new String();
try {
System.out.println(path);
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while((thisLine = bufferedReader.readLine()) != null) {
result += thisLine;
}
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
return result;
}
ReadAllBytes方法
public byte[] ReadAllBytes (String path) {
byte[] result = new byte[100];
try {
fileInputStream = new FileInputStream(path);
//dataInputStream = new DataInputStream(fileInputStream);
fileInputStream.read(result,0,result.length);
fileInputStream.close();
}
catch(Exception ex) {
}
return result;
}
WriteAllBytes方法
public void WriteAllBytes(String path, byte[] Text) {
try {
fileOutputStream = new FileOutputStream(path);
fileOutputStream.write(Text);
fileOutputStream.flush();
fileOutputStream.close();
}
catch(Exception ex) {
}
}
Create方法
public void Create(String path) {
try {
file = new File(path);
file.createNewFile();
file = null;
}
catch(Exception ex) {
}
}
Copy方法
public void Copy(String path1, String path2) {
try {
byte[] text = ReadAllBytes(path1);
//创建新文件
Create(path2);
//开始写入
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
Delete方法
public void Delete(String path) {
try {
file = new File(path);
file.delete();
file = null;
}
catch(Exception ex) {
}
}
Exists方法
public boolean Exists(String path) {
file = new File(path);
boolean result = file.exists();
file = null;
return result;
}
Move方法
public void Move(String path1, String path2) {
try {
//1.读取并删除旧文件
byte[] text = ReadAllBytes(path1);
Delete(path1);
//2.创建新文件
Create(path2);
//3.写入新文件
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
ReadAllLines方法
public String[] ReadAllLines(String path) {
file = new File(path);
String[] result = new String[(int)file.length()];
int i = 0;
try {
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while( (thisLine = bufferedReader.readLine()) != null ) {
result[i] = thisLine;
i++;
}
bufferedReader.close();
}
catch(Exception ex) {
}
return result;
}
WriteAllLines方法
public void WriteAllLines(String path,String[] Text) {
try {
System.out.println(Text);
fileWriter = new FileWriter(path);
System.out.println(path);
bufferedWriter = new BufferedWriter(fileWriter);
for(int i = 0;i < Text.length;i++) {
bufferedWriter.write(Text[i] + "rn");
System.out.println(Text[i].toString());
}
bufferedWriter.flush();
fileWriter.close();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
public void InitializeAllPath() {
thisLine = new String();
fileWriter = null;
fileReader = null;
bufferedReader = null;
bufferedWriter = null;
fileInputStream = null;
fileOutputStream = null;
dataInputStream = null;
file = null;
}
AppendAllLines方法
public void AppendAllLines(String path, String[] Text) {
try {
fileWriter = new FileWriter(path);
bufferedWriter = new BufferedWriter(fileWriter);
String thisLine = new String();
for(int i = 0;i < Text.length;i++) {
thisLine = Text[i];
bufferedWriter.write(thisLine + "rn");
}
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
AppendAllText方法
public void AppendAllText(String path, String Text) {
try {
//1.读取现有文件
String Text_now = ReadAllText(path);
//2.写入现有内容和新内容
fileWriter = new FileWriter(path);
bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(Text_now + Text);
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
WriteAllText方法
public void WriteAllText(String path, String Text) {
try {
fileWriter = new FileWriter(path);
bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(Text);
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
ReadAllText方法
public String ReadAllText(String path) {
String result = new String();
try {
System.out.println(path);
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while((thisLine = bufferedReader.readLine()) != null) {
result += thisLine;
}
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
return result;
}
ReadAllBytes方法
public byte[] ReadAllBytes (String path) {
byte[] result = new byte[100];
try {
fileInputStream = new FileInputStream(path);
//dataInputStream = new DataInputStream(fileInputStream);
fileInputStream.read(result,0,result.length);
fileInputStream.close();
}
catch(Exception ex) {
}
return result;
}
WriteAllBytes方法
public void WriteAllBytes(String path, byte[] Text) {
try {
fileOutputStream = new FileOutputStream(path);
fileOutputStream.write(Text);
fileOutputStream.flush();
fileOutputStream.close();
}
catch(Exception ex) {
}
}
Create方法
public void Create(String path) {
try {
file = new File(path);
file.createNewFile();
file = null;
}
catch(Exception ex) {
}
}
Copy方法
public void Copy(String path1, String path2) {
try {
byte[] text = ReadAllBytes(path1);
//创建新文件
Create(path2);
//开始写入
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
Delete方法
public void Delete(String path) {
try {
file = new File(path);
file.delete();
file = null;
}
catch(Exception ex) {
}
}
Exists方法
public boolean Exists(String path) {
file = new File(path);
boolean result = file.exists();
file = null;
return result;
}
Move方法
public void Move(String path1, String path2) {
try {
//1.读取并删除旧文件
byte[] text = ReadAllBytes(path1);
Delete(path1);
//2.创建新文件
Create(path2);
//3.写入新文件
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
ReadAllLines方法
public String[] ReadAllLines(String path) {
file = new File(path);
String[] result = new String[(int)file.length()];
int i = 0;
try {
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while( (thisLine = bufferedReader.readLine()) != null ) {
result[i] = thisLine;
i++;
}
bufferedReader.close();
}
catch(Exception ex) {
}
return result;
}
WriteAllLines方法
public void WriteAllLines(String path,String[] Text) {
try {
System.out.println(Text);
fileWriter = new FileWriter(path);
System.out.println(path);
bufferedWriter = new BufferedWriter(fileWriter);
for(int i = 0;i < Text.length;i++) {
bufferedWriter.write(Text[i] + "rn");
System.out.println(Text[i].toString());
}
bufferedWriter.flush();
fileWriter.close();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
public void AppendAllText(String path, String Text) {
try {
//1.读取现有文件
String Text_now = ReadAllText(path);
//2.写入现有内容和新内容
fileWriter = new FileWriter(path);
bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(Text_now + Text);
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
WriteAllText方法
public void WriteAllText(String path, String Text) {
try {
fileWriter = new FileWriter(path);
bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(Text);
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
ReadAllText方法
public String ReadAllText(String path) {
String result = new String();
try {
System.out.println(path);
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while((thisLine = bufferedReader.readLine()) != null) {
result += thisLine;
}
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
return result;
}
ReadAllBytes方法
public byte[] ReadAllBytes (String path) {
byte[] result = new byte[100];
try {
fileInputStream = new FileInputStream(path);
//dataInputStream = new DataInputStream(fileInputStream);
fileInputStream.read(result,0,result.length);
fileInputStream.close();
}
catch(Exception ex) {
}
return result;
}
WriteAllBytes方法
public void WriteAllBytes(String path, byte[] Text) {
try {
fileOutputStream = new FileOutputStream(path);
fileOutputStream.write(Text);
fileOutputStream.flush();
fileOutputStream.close();
}
catch(Exception ex) {
}
}
Create方法
public void Create(String path) {
try {
file = new File(path);
file.createNewFile();
file = null;
}
catch(Exception ex) {
}
}
Copy方法
public void Copy(String path1, String path2) {
try {
byte[] text = ReadAllBytes(path1);
//创建新文件
Create(path2);
//开始写入
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
Delete方法
public void Delete(String path) {
try {
file = new File(path);
file.delete();
file = null;
}
catch(Exception ex) {
}
}
Exists方法
public boolean Exists(String path) {
file = new File(path);
boolean result = file.exists();
file = null;
return result;
}
Move方法
public void Move(String path1, String path2) {
try {
//1.读取并删除旧文件
byte[] text = ReadAllBytes(path1);
Delete(path1);
//2.创建新文件
Create(path2);
//3.写入新文件
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
ReadAllLines方法
public String[] ReadAllLines(String path) {
file = new File(path);
String[] result = new String[(int)file.length()];
int i = 0;
try {
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while( (thisLine = bufferedReader.readLine()) != null ) {
result[i] = thisLine;
i++;
}
bufferedReader.close();
}
catch(Exception ex) {
}
return result;
}
WriteAllLines方法
public void WriteAllLines(String path,String[] Text) {
try {
System.out.println(Text);
fileWriter = new FileWriter(path);
System.out.println(path);
bufferedWriter = new BufferedWriter(fileWriter);
for(int i = 0;i < Text.length;i++) {
bufferedWriter.write(Text[i] + "rn");
System.out.println(Text[i].toString());
}
bufferedWriter.flush();
fileWriter.close();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
public String ReadAllText(String path) {
String result = new String();
try {
System.out.println(path);
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while((thisLine = bufferedReader.readLine()) != null) {
result += thisLine;
}
bufferedWriter.flush();
bufferedWriter.close();
}
catch(Exception ex) {
}
return result;
}
ReadAllBytes方法
public byte[] ReadAllBytes (String path) {
byte[] result = new byte[100];
try {
fileInputStream = new FileInputStream(path);
//dataInputStream = new DataInputStream(fileInputStream);
fileInputStream.read(result,0,result.length);
fileInputStream.close();
}
catch(Exception ex) {
}
return result;
}
WriteAllBytes方法
public void WriteAllBytes(String path, byte[] Text) {
try {
fileOutputStream = new FileOutputStream(path);
fileOutputStream.write(Text);
fileOutputStream.flush();
fileOutputStream.close();
}
catch(Exception ex) {
}
}
Create方法
public void Create(String path) {
try {
file = new File(path);
file.createNewFile();
file = null;
}
catch(Exception ex) {
}
}
Copy方法
public void Copy(String path1, String path2) {
try {
byte[] text = ReadAllBytes(path1);
//创建新文件
Create(path2);
//开始写入
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
Delete方法
public void Delete(String path) {
try {
file = new File(path);
file.delete();
file = null;
}
catch(Exception ex) {
}
}
Exists方法
public boolean Exists(String path) {
file = new File(path);
boolean result = file.exists();
file = null;
return result;
}
Move方法
public void Move(String path1, String path2) {
try {
//1.读取并删除旧文件
byte[] text = ReadAllBytes(path1);
Delete(path1);
//2.创建新文件
Create(path2);
//3.写入新文件
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
ReadAllLines方法
public String[] ReadAllLines(String path) {
file = new File(path);
String[] result = new String[(int)file.length()];
int i = 0;
try {
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while( (thisLine = bufferedReader.readLine()) != null ) {
result[i] = thisLine;
i++;
}
bufferedReader.close();
}
catch(Exception ex) {
}
return result;
}
WriteAllLines方法
public void WriteAllLines(String path,String[] Text) {
try {
System.out.println(Text);
fileWriter = new FileWriter(path);
System.out.println(path);
bufferedWriter = new BufferedWriter(fileWriter);
for(int i = 0;i < Text.length;i++) {
bufferedWriter.write(Text[i] + "rn");
System.out.println(Text[i].toString());
}
bufferedWriter.flush();
fileWriter.close();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
public void WriteAllBytes(String path, byte[] Text) {
try {
fileOutputStream = new FileOutputStream(path);
fileOutputStream.write(Text);
fileOutputStream.flush();
fileOutputStream.close();
}
catch(Exception ex) {
}
}
Create方法
public void Create(String path) {
try {
file = new File(path);
file.createNewFile();
file = null;
}
catch(Exception ex) {
}
}
Copy方法
public void Copy(String path1, String path2) {
try {
byte[] text = ReadAllBytes(path1);
//创建新文件
Create(path2);
//开始写入
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
Delete方法
public void Delete(String path) {
try {
file = new File(path);
file.delete();
file = null;
}
catch(Exception ex) {
}
}
Exists方法
public boolean Exists(String path) {
file = new File(path);
boolean result = file.exists();
file = null;
return result;
}
Move方法
public void Move(String path1, String path2) {
try {
//1.读取并删除旧文件
byte[] text = ReadAllBytes(path1);
Delete(path1);
//2.创建新文件
Create(path2);
//3.写入新文件
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
ReadAllLines方法
public String[] ReadAllLines(String path) {
file = new File(path);
String[] result = new String[(int)file.length()];
int i = 0;
try {
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while( (thisLine = bufferedReader.readLine()) != null ) {
result[i] = thisLine;
i++;
}
bufferedReader.close();
}
catch(Exception ex) {
}
return result;
}
WriteAllLines方法
public void WriteAllLines(String path,String[] Text) {
try {
System.out.println(Text);
fileWriter = new FileWriter(path);
System.out.println(path);
bufferedWriter = new BufferedWriter(fileWriter);
for(int i = 0;i < Text.length;i++) {
bufferedWriter.write(Text[i] + "rn");
System.out.println(Text[i].toString());
}
bufferedWriter.flush();
fileWriter.close();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
public void Copy(String path1, String path2) {
try {
byte[] text = ReadAllBytes(path1);
//创建新文件
Create(path2);
//开始写入
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
Delete方法
public void Delete(String path) {
try {
file = new File(path);
file.delete();
file = null;
}
catch(Exception ex) {
}
}
Exists方法
public boolean Exists(String path) {
file = new File(path);
boolean result = file.exists();
file = null;
return result;
}
Move方法
public void Move(String path1, String path2) {
try {
//1.读取并删除旧文件
byte[] text = ReadAllBytes(path1);
Delete(path1);
//2.创建新文件
Create(path2);
//3.写入新文件
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
ReadAllLines方法
public String[] ReadAllLines(String path) {
file = new File(path);
String[] result = new String[(int)file.length()];
int i = 0;
try {
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while( (thisLine = bufferedReader.readLine()) != null ) {
result[i] = thisLine;
i++;
}
bufferedReader.close();
}
catch(Exception ex) {
}
return result;
}
WriteAllLines方法
public void WriteAllLines(String path,String[] Text) {
try {
System.out.println(Text);
fileWriter = new FileWriter(path);
System.out.println(path);
bufferedWriter = new BufferedWriter(fileWriter);
for(int i = 0;i < Text.length;i++) {
bufferedWriter.write(Text[i] + "rn");
System.out.println(Text[i].toString());
}
bufferedWriter.flush();
fileWriter.close();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
public boolean Exists(String path) {
file = new File(path);
boolean result = file.exists();
file = null;
return result;
}
Move方法
public void Move(String path1, String path2) {
try {
//1.读取并删除旧文件
byte[] text = ReadAllBytes(path1);
Delete(path1);
//2.创建新文件
Create(path2);
//3.写入新文件
WriteAllBytes(path2,text);
}
catch(Exception ex) {
}
}
ReadAllLines方法
public String[] ReadAllLines(String path) {
file = new File(path);
String[] result = new String[(int)file.length()];
int i = 0;
try {
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while( (thisLine = bufferedReader.readLine()) != null ) {
result[i] = thisLine;
i++;
}
bufferedReader.close();
}
catch(Exception ex) {
}
return result;
}
WriteAllLines方法
public void WriteAllLines(String path,String[] Text) {
try {
System.out.println(Text);
fileWriter = new FileWriter(path);
System.out.println(path);
bufferedWriter = new BufferedWriter(fileWriter);
for(int i = 0;i < Text.length;i++) {
bufferedWriter.write(Text[i] + "rn");
System.out.println(Text[i].toString());
}
bufferedWriter.flush();
fileWriter.close();
bufferedWriter.close();
}
catch(Exception ex) {
}
}
public String[] ReadAllLines(String path) {
file = new File(path);
String[] result = new String[(int)file.length()];
int i = 0;
try {
fileReader = new FileReader(path);
bufferedReader = new BufferedReader(fileReader);
while( (thisLine = bufferedReader.readLine()) != null ) {
result[i] = thisLine;
i++;
}
bufferedReader.close();
}
catch(Exception ex) {
}
return result;
}



