import android.util.Log;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class File_reader_tool {
public static String TAG="File_reader_tool";
public interface Get_String_line_event{
public void get_string(String line);
}
public Get_String_line_event event=null;
public void load(File file){
if(event==null)return;
FileInputStream is;
BufferedReader reader;
try {
is = new FileInputStream(file);
reader = new BufferedReader(new InputStreamReader(is));
String line = reader.readLine();
while (line != null) {
// Log.d("TTT", line);
event.get_string(line);
line = reader.readLine();
}
is.close();
reader.close();
}catch (Exception e){
Log.e(TAG,e.getMessage());
}
}
}
使用方法:
File_reader_tool reader_tool=new File_reader_tool();
reader_tool.event=new File_reader_tool.Get_String_line_event() {
@Override
public void get_string(String line) {
//字串處理
}
};
File file = new File("your path");
reader_tool.load(file);
沒有留言:
張貼留言