- 浏览: 38780 次
- 性别:
- 来自: 北京
文章分类
最新评论
文件读写工具类
1、文本文件读写工具类
view plain
<span style="font-size:16px;">package mine.util;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
* 此工具类用于文本文件的读写
*
* @author Touch
*/
public class TextFile {
// 读取指定路径文本文件
public static String read(String filePath) {
StringBuilder str = new StringBuilder();
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(filePath));
String s;
try {
while ((s = in.readLine()) != null)
str.append(s + '\n');
} finally {
in.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str.toString();
}
// 写入指定的文本文件,append为true表示追加,false表示重头开始写,
//text是要写入的文本字符串,text为null时直接返回
public static void write(String filePath, boolean append, String text) {
if (text == null)
return;
try {
BufferedWriter out = new BufferedWriter(new FileWriter(filePath,
append));
try {
out.write(text);
} finally {
out.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
</span>
view plain
<span style="font-size:16px;">package mine.util;
public class TestTextFile {
public static void main(String[] args) {
TextFile.write("file/textfile.txt", false,
"这是一个文本文件的读写测试\nTouch\n刘海房\n男\n");
TextFile.write("file/textfile.txt", true, "武汉工业学院\n软件工程");
System.out.println(TextFile.read("file/textfile.txt"));
}
}
</span>
2、二进制文件读写工具类
view plain
<span style="font-size:16px;">package mine.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* 此工具类用于二进制文件的读写
*
* @author Touch
*/
public class BinaryFile {
// 把二进制文件读入字节数组,如果没有内容,字节数组为null
public static byte[] read(String filePath) {
byte[] data = null;
try {
BufferedInputStream in = new BufferedInputStream(
new FileInputStream(filePath));
try {
data = new byte[in.available()];
in.read(data);
} finally {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
return data;
}
// 把字节数组为写入二进制文件,数组为null时直接返回
public static void write(String filePath, byte[] data) {
if (data == null)
return;
try {
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(filePath));
try {
out.write(data);
} finally {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
</span>
view plain
<span style="font-size:16px;">package mine.util;
import java.util.Arrays;
public class TestBinaryFile {
public static void main(String[] args) {
BinaryFile.write("file/binaryfile.dat", new byte[] { 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 'a', 'b', 'c' });
byte[] data = BinaryFile.read("file/binaryfile.dat");
System.out.println(Arrays.toString(data));
}
}
</span>
3、对象读写工具类(有问题,在读取多个对象时有问题,怎样把一个对象文件中的所有对象读出来?)
view plain
<span style="font-size:16px;">package mine.util;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* 此类用于对象的读写
*
* @author Touch
*/
public class ObjectFile {
// 把一个对象写入文件,isAppend为true表示追加方式写,false表示重新写
public static void write(String filePath, Object o, boolean isAppend) {
if (o == null)
return;
try {
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream(filePath, isAppend));
try {
out.writeObject(o);
} finally {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
// 把一个对象数组写入文件,isAppend为true表示追加方式写,false表示重新写
public static void write(String filePath, Object[] objects, boolean isAppend) {
if (objects == null)
return;
try {
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream(filePath, isAppend));
try {
for (Object o : objects)
out.writeObject(o);
} finally {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
// 读取对象,返回一个对象
public static Object read(String filePath) {
Object o = null;
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(
filePath));
try {
o = in.readObject();
} finally {
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return o;
}
// 读取对象,返回一个对象数组,count表示要读的对象的个数
public static Object[] read(String filePath, int count) {
Object[] objects = new Object[count];
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(
filePath));
try {
for (int i = 0; i < count; i++) {
//第二次调用in.readObject()就抛出异常,这是为什么?
objects[i] = in.readObject();
}
} finally {
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return objects;
}
}
</span>
view plain
<span style="font-size:16px;">package mine.util;
import java.io.Serializable;
public class TestObjectFile {
public static void main(String[] args) {
ObjectFile.write("file/object1", new Person(), false);
ObjectFile.write("file/object1", new Person(), true);
ObjectFile.write("file/object1", new Person[] { new Person("Touch", 1),
new Person("Rainbow", 0), new Person() }, true);
for (Object o : ObjectFile.read("file/object1", 5))
((Person) o).display();
}
}
class Person implements Serializable {
private String name = "刘海房";
private int sex = 0;
Person(String name, int sex) {
this.name = name;
this.sex = sex;
}
Person() {
}
void display() {
System.out.println("my name is :" + name);
String s = (sex == 0) ? "男" : "女";
System.out.println("性别:" + s);
}
}</span>
4、对象读写工具类(解决了3中的问题,能够写入及读取多个对象)
3中到底问题出在哪呢?先来看一段ObjectOutputStream构造方法的源代码,此源代码来自jdk1.6版。
view plain
<span style="font-size:16px;"> public ObjectOutputStream(OutputStream out) throws IOException {
verifySubclass();
bout = new BlockDataOutputStream(out);
handles = new HandleTable(10, (float) 3.00);
subs = new ReplaceTable(10, (float) 3.00);
enableOverride = false;
</span><span style="font-size:16px;"><span style="color:#ff0000;">writeStreamHeader();
</span> bout.setBlockDataMode(true);
if (extendedDebugInfo) {
debugInfoStack = new DebugTraceInfoStack();
} else {
debugInfoStack = null;
}
}</span>
这段代码中我们只需要关注writeStreamHeader();方法,这个方法在源代码中的解释是
view plain
<span style="font-size:16px;"> /**
* The writeStreamHeader method is provided so subclasses can append or
* prepend their own header to the stream. It writes the magic number and
* version to the stream.
*
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/</span>
也就是说我们打开(new)一个ObjectOutputStream的时候,这个ObjectOutputStream流中就已经被写入了一些信息,这些信息会写入到我们的文件中。在第一次写入文件时,这些头部信息时需要的,因为ObjectInputStream读的时候会帮我们过滤掉。但是当我们追加写入一个文件时,这些头部信息也会写入文件中,读取的时候只会把文件第一次出现的头部信息过滤掉,并不会把文件中间的头部信息也过滤掉,这就是问题的根源所在。
怎么解决呢?正如lichong_87提到的
一、可以在每次写入的时候把文件中所有对象读出来,然后重新写入,这种方法效率比较低。
二、如果不是第一次写入文件,在写入时去掉头部信息,怎么去掉呢?头部信息是在writeStreamHeader();方法中写入的,所以我们可以通过继承ObjectOutputStream来覆盖这个方法,如果不是第一次写入文件,这个方法什么也不做。
下面是第二种解决方案的源代码及测试
view plain
<span style="font-size:16px;">package mine.util.io;
import java.io.File;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
/**
* 此类继承ObjectOutputStream,重写writeStreamHeader()方法,以实现追加写入时去掉头部信息
*/
public class MyObjectOutputStream extends ObjectOutputStream {
private static File f;
// writeStreamHeader()方法是在ObjectOutputStream的构造方法里调用的
// 由于覆盖后的writeStreamHeader()方法用到了f。如果直接用此构造方法创建
// 一个MyObjectOutputStream对象,那么writeStreamHeader()中的f是空指针
// 因为f还没有初始化。所以这里采用单态模式
private MyObjectOutputStream(OutputStream out, File f) throws IOException,
SecurityException {
super(out);
}
// 返回一个MyObjectOutputStream对象,这里保证了new MyObjectOutputStream(out, f)
// 之前f已经指向一个File对象
public static MyObjectOutputStream newInstance(File file, OutputStream out)
throws IOException {
f = file;// 本方法最重要的地方:构建文件对象,两个引用指向同一个文件对象
return new MyObjectOutputStream(out, f);
}
@Override
protected void writeStreamHeader() throws IOException {
// 文件不存在或文件为空,此时是第一次写入文件,所以要把头部信息写入。
if (!f.exists() || (f.exists() && f.length() == 0)) {
super.writeStreamHeader();
} else {
// 不需要做任何事情
}
}
}
</span>
view plain
<span style="font-size:16px;">package mine.util.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
/**
* 此类用于对象的读写
*
* @author Touch
*/
public class ObjectFile {
// 把一个对象写入文件,isAppend为true表示追加方式写,false表示重新写
public static void write(String filePath, Object o, boolean isAppend) {
if (o == null)
return;
try {
File f = new File(filePath);
MyObjectOutputStream out = MyObjectOutputStream.newInstance(f,
new FileOutputStream(f, isAppend));
try {
out.writeObject(o);
} finally {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
// 把一个对象数组写入文件,isAppend为true表示追加方式写,false表示重新写
public static void write(String filePath, Object[] objects, boolean isAppend) {
if (objects == null)
return;
try {
File f = new File(filePath);
MyObjectOutputStream out = MyObjectOutputStream.newInstance(f,
new FileOutputStream(f, isAppend));
try {
for (Object o : objects)
out.writeObject(o);
} finally {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
// 读取对象,返回一个对象
public static Object read(String filePath) {
Object o = null;
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(
filePath));
try {
o = in.readObject();
} finally {
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return o;
}
// 读取对象,返回一个对象数组,count表示要读的对象的个数
public static Object[] read(String filePath, int count) {
Object[] objects = new Object[count];
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(
filePath));
try {
for (int i = 0; i < count; i++) {
objects[i] = in.readObject();
}
} finally {
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return objects;
}
}
</span>
view plain
<span style="font-size:16px;">package mine.util.io;
import java.io.Serializable;
public class TestObjectFile {
public static void main(String[] args) {
ObjectFile.write("file/t.dat", new Person(), false);
ObjectFile.write("file/t.dat", new Person(), true);
ObjectFile.write("file/t.dat", new Person[] { new Person("Touch", 1),
new Person("Rainbow", 0), new Person() }, true);
for (Object o : ObjectFile.read("file/t.dat", 5))
((Person) o).display();
}
}
class Person implements Serializable {
private static final long serialVersionUID = 1L;
private String name = "刘海房";
private int sex = 0;
Person(String name, int sex) {
this.name = name;
this.sex = sex;
}
Person() {
}
void display() {
System.out.println("my name is :" + name);
String s = (sex == 0) ? "男" : "女";
System.out.println("性别:" + s);
}
}</span>
运行结果:
my name is :刘海房
性别:男
my name is :刘海房
性别:男
my name is :Touch
性别:女
my name is :Rainbow
性别:男
my name is :刘海房
性别:男
view plain
<span style="font-size:16px;">package mine.util;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
* 此工具类用于文本文件的读写
*
* @author Touch
*/
public class TextFile {
// 读取指定路径文本文件
public static String read(String filePath) {
StringBuilder str = new StringBuilder();
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(filePath));
String s;
try {
while ((s = in.readLine()) != null)
str.append(s + '\n');
} finally {
in.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str.toString();
}
// 写入指定的文本文件,append为true表示追加,false表示重头开始写,
//text是要写入的文本字符串,text为null时直接返回
public static void write(String filePath, boolean append, String text) {
if (text == null)
return;
try {
BufferedWriter out = new BufferedWriter(new FileWriter(filePath,
append));
try {
out.write(text);
} finally {
out.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
</span>
view plain
<span style="font-size:16px;">package mine.util;
public class TestTextFile {
public static void main(String[] args) {
TextFile.write("file/textfile.txt", false,
"这是一个文本文件的读写测试\nTouch\n刘海房\n男\n");
TextFile.write("file/textfile.txt", true, "武汉工业学院\n软件工程");
System.out.println(TextFile.read("file/textfile.txt"));
}
}
</span>
2、二进制文件读写工具类
view plain
<span style="font-size:16px;">package mine.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* 此工具类用于二进制文件的读写
*
* @author Touch
*/
public class BinaryFile {
// 把二进制文件读入字节数组,如果没有内容,字节数组为null
public static byte[] read(String filePath) {
byte[] data = null;
try {
BufferedInputStream in = new BufferedInputStream(
new FileInputStream(filePath));
try {
data = new byte[in.available()];
in.read(data);
} finally {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
return data;
}
// 把字节数组为写入二进制文件,数组为null时直接返回
public static void write(String filePath, byte[] data) {
if (data == null)
return;
try {
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(filePath));
try {
out.write(data);
} finally {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
</span>
view plain
<span style="font-size:16px;">package mine.util;
import java.util.Arrays;
public class TestBinaryFile {
public static void main(String[] args) {
BinaryFile.write("file/binaryfile.dat", new byte[] { 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 'a', 'b', 'c' });
byte[] data = BinaryFile.read("file/binaryfile.dat");
System.out.println(Arrays.toString(data));
}
}
</span>
3、对象读写工具类(有问题,在读取多个对象时有问题,怎样把一个对象文件中的所有对象读出来?)
view plain
<span style="font-size:16px;">package mine.util;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* 此类用于对象的读写
*
* @author Touch
*/
public class ObjectFile {
// 把一个对象写入文件,isAppend为true表示追加方式写,false表示重新写
public static void write(String filePath, Object o, boolean isAppend) {
if (o == null)
return;
try {
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream(filePath, isAppend));
try {
out.writeObject(o);
} finally {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
// 把一个对象数组写入文件,isAppend为true表示追加方式写,false表示重新写
public static void write(String filePath, Object[] objects, boolean isAppend) {
if (objects == null)
return;
try {
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream(filePath, isAppend));
try {
for (Object o : objects)
out.writeObject(o);
} finally {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
// 读取对象,返回一个对象
public static Object read(String filePath) {
Object o = null;
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(
filePath));
try {
o = in.readObject();
} finally {
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return o;
}
// 读取对象,返回一个对象数组,count表示要读的对象的个数
public static Object[] read(String filePath, int count) {
Object[] objects = new Object[count];
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(
filePath));
try {
for (int i = 0; i < count; i++) {
//第二次调用in.readObject()就抛出异常,这是为什么?
objects[i] = in.readObject();
}
} finally {
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return objects;
}
}
</span>
view plain
<span style="font-size:16px;">package mine.util;
import java.io.Serializable;
public class TestObjectFile {
public static void main(String[] args) {
ObjectFile.write("file/object1", new Person(), false);
ObjectFile.write("file/object1", new Person(), true);
ObjectFile.write("file/object1", new Person[] { new Person("Touch", 1),
new Person("Rainbow", 0), new Person() }, true);
for (Object o : ObjectFile.read("file/object1", 5))
((Person) o).display();
}
}
class Person implements Serializable {
private String name = "刘海房";
private int sex = 0;
Person(String name, int sex) {
this.name = name;
this.sex = sex;
}
Person() {
}
void display() {
System.out.println("my name is :" + name);
String s = (sex == 0) ? "男" : "女";
System.out.println("性别:" + s);
}
}</span>
4、对象读写工具类(解决了3中的问题,能够写入及读取多个对象)
3中到底问题出在哪呢?先来看一段ObjectOutputStream构造方法的源代码,此源代码来自jdk1.6版。
view plain
<span style="font-size:16px;"> public ObjectOutputStream(OutputStream out) throws IOException {
verifySubclass();
bout = new BlockDataOutputStream(out);
handles = new HandleTable(10, (float) 3.00);
subs = new ReplaceTable(10, (float) 3.00);
enableOverride = false;
</span><span style="font-size:16px;"><span style="color:#ff0000;">writeStreamHeader();
</span> bout.setBlockDataMode(true);
if (extendedDebugInfo) {
debugInfoStack = new DebugTraceInfoStack();
} else {
debugInfoStack = null;
}
}</span>
这段代码中我们只需要关注writeStreamHeader();方法,这个方法在源代码中的解释是
view plain
<span style="font-size:16px;"> /**
* The writeStreamHeader method is provided so subclasses can append or
* prepend their own header to the stream. It writes the magic number and
* version to the stream.
*
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/</span>
也就是说我们打开(new)一个ObjectOutputStream的时候,这个ObjectOutputStream流中就已经被写入了一些信息,这些信息会写入到我们的文件中。在第一次写入文件时,这些头部信息时需要的,因为ObjectInputStream读的时候会帮我们过滤掉。但是当我们追加写入一个文件时,这些头部信息也会写入文件中,读取的时候只会把文件第一次出现的头部信息过滤掉,并不会把文件中间的头部信息也过滤掉,这就是问题的根源所在。
怎么解决呢?正如lichong_87提到的
一、可以在每次写入的时候把文件中所有对象读出来,然后重新写入,这种方法效率比较低。
二、如果不是第一次写入文件,在写入时去掉头部信息,怎么去掉呢?头部信息是在writeStreamHeader();方法中写入的,所以我们可以通过继承ObjectOutputStream来覆盖这个方法,如果不是第一次写入文件,这个方法什么也不做。
下面是第二种解决方案的源代码及测试
view plain
<span style="font-size:16px;">package mine.util.io;
import java.io.File;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
/**
* 此类继承ObjectOutputStream,重写writeStreamHeader()方法,以实现追加写入时去掉头部信息
*/
public class MyObjectOutputStream extends ObjectOutputStream {
private static File f;
// writeStreamHeader()方法是在ObjectOutputStream的构造方法里调用的
// 由于覆盖后的writeStreamHeader()方法用到了f。如果直接用此构造方法创建
// 一个MyObjectOutputStream对象,那么writeStreamHeader()中的f是空指针
// 因为f还没有初始化。所以这里采用单态模式
private MyObjectOutputStream(OutputStream out, File f) throws IOException,
SecurityException {
super(out);
}
// 返回一个MyObjectOutputStream对象,这里保证了new MyObjectOutputStream(out, f)
// 之前f已经指向一个File对象
public static MyObjectOutputStream newInstance(File file, OutputStream out)
throws IOException {
f = file;// 本方法最重要的地方:构建文件对象,两个引用指向同一个文件对象
return new MyObjectOutputStream(out, f);
}
@Override
protected void writeStreamHeader() throws IOException {
// 文件不存在或文件为空,此时是第一次写入文件,所以要把头部信息写入。
if (!f.exists() || (f.exists() && f.length() == 0)) {
super.writeStreamHeader();
} else {
// 不需要做任何事情
}
}
}
</span>
view plain
<span style="font-size:16px;">package mine.util.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
/**
* 此类用于对象的读写
*
* @author Touch
*/
public class ObjectFile {
// 把一个对象写入文件,isAppend为true表示追加方式写,false表示重新写
public static void write(String filePath, Object o, boolean isAppend) {
if (o == null)
return;
try {
File f = new File(filePath);
MyObjectOutputStream out = MyObjectOutputStream.newInstance(f,
new FileOutputStream(f, isAppend));
try {
out.writeObject(o);
} finally {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
// 把一个对象数组写入文件,isAppend为true表示追加方式写,false表示重新写
public static void write(String filePath, Object[] objects, boolean isAppend) {
if (objects == null)
return;
try {
File f = new File(filePath);
MyObjectOutputStream out = MyObjectOutputStream.newInstance(f,
new FileOutputStream(f, isAppend));
try {
for (Object o : objects)
out.writeObject(o);
} finally {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
// 读取对象,返回一个对象
public static Object read(String filePath) {
Object o = null;
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(
filePath));
try {
o = in.readObject();
} finally {
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return o;
}
// 读取对象,返回一个对象数组,count表示要读的对象的个数
public static Object[] read(String filePath, int count) {
Object[] objects = new Object[count];
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(
filePath));
try {
for (int i = 0; i < count; i++) {
objects[i] = in.readObject();
}
} finally {
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return objects;
}
}
</span>
view plain
<span style="font-size:16px;">package mine.util.io;
import java.io.Serializable;
public class TestObjectFile {
public static void main(String[] args) {
ObjectFile.write("file/t.dat", new Person(), false);
ObjectFile.write("file/t.dat", new Person(), true);
ObjectFile.write("file/t.dat", new Person[] { new Person("Touch", 1),
new Person("Rainbow", 0), new Person() }, true);
for (Object o : ObjectFile.read("file/t.dat", 5))
((Person) o).display();
}
}
class Person implements Serializable {
private static final long serialVersionUID = 1L;
private String name = "刘海房";
private int sex = 0;
Person(String name, int sex) {
this.name = name;
this.sex = sex;
}
Person() {
}
void display() {
System.out.println("my name is :" + name);
String s = (sex == 0) ? "男" : "女";
System.out.println("性别:" + s);
}
}</span>
运行结果:
my name is :刘海房
性别:男
my name is :刘海房
性别:男
my name is :Touch
性别:女
my name is :Rainbow
性别:男
my name is :刘海房
性别:男
相关推荐
完整的java文件读写工具类 包括读取、创建、删除文件, 检查、创建、删除目录
PropertyUtil配置文件读写工具类,超级简便的代码,超级实用
很好的文件操作工具类 好东西要分享
自己封装的一些文件(夹)操作和txt文件读写的工具类 哈哈(ExtUtil)感兴趣的可以看看,^_^
主要为大家详细介绍了java文件读写工具类,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
java通过snakeyaml类能非常方便的操作,读写yaml文件。
本人没分了,特别来分享一下,通用的XML读写工具类,同志们下下绝对不后悔
C# 文件工具类 实际项目使用 久经考验 文件读写 复制 删除 创建文件夹 判断文件扩展名等等
添加文件读写工具类 添加glide网络图片加载工具类 添加wifi操作工具类 2018.1.3 丰富了手机工具类的方法集 添加蓝牙工具类方法集、蓝牙扫描回调接口 wifi工具类添加连接指令wifi方法 2018.1.9 修复一些...
一个非常好用的csv文件操作工具
内容:博客代码 一次代码重构之旅-快速读写xml文件工具类封装 http://blog.csdn.net/lk_blog/article/details/8220803
本文实例为大家分享了Android读写文件工具类的具体代码,供大家参考,具体内容如下 public class Utils { private static String path1 = Environment.getExternalStorageDirectory().getAbsolutePath(); private...
大家可以不用在为操作文件发愁了! 小弟觉得这个工具类还不是很完善,高手在帮忙完善一下,别忘了共享出来哦!
将ini读写制作成工具类,直接建立工程,将文件.h,.cpp添加,然后直接调用即可,在文件目录下建立ini文件,读写直接调用函数即可
亲测可用,代码简洁易懂,可以直接上手对Excel文件进行读写。应用于非MFC环境,对Excel中数字,字符串,日期,布尔型等多种数据都可以读写。
最近在整理自己电脑的音乐文件,希望音乐tag标签信息能使用java程序批量处理,网上找了相关资料,发现有一个老外写的工具类org.jaudiotagger可以满足需要,但在使用过程中发现读取中文变成乱码问题,然后我把这个...
读/写属性文件的工具类. PropertyUtil.java对Property文件读写进行了封装, 使开发人员对Property文件的读写更加容易。 在性能、实用性 方面还是可以的。
INI文件读写类
基于dom4j的读写xml文件的工具包。封装了dom4j操作xml文档的常和方法。 支持两种读写方法。1:针对小文件的读取整个文档,2:针对大文件的,逐行读取。读到几百M文件毫无压力。
自己封装的一些文件(夹)操作和txt文件读写的工具类,里面有源码、jar包,和文档