Android 文件 File 读写
2010-08-23 11:29:00 来源:WEB开发网return EncodingUtils.getString(array,TEXT_ENCODING);
}
5. 文件长度
Java代码
public int length(){
return (int)file.length();
}
public int length(){
return (int)file.length();
}
6. 如何使用FileIOHelper
Java代码
public class FileIOUsage extends Activity {
public final static String NAME = "griffinshi.txt";
public final static String PATH = "data/data/com.android.FileIO";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
try {
FileIOHelper helper = new FileIOHelper(this,NAME,PATH );
String string = "Hello to Gryphone!";
helper.wrire(string);
byte[] array = helper.read(0, helper.length());
String data = helper.encode(array);
TextView tv = new TextView(this);
tv.setText(data);
setContentView(tv);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class FileIOUsage extends Activity {
public final static String NAME = "griffinshi.txt";
public final static String PATH = "data/data/com.android.FileIO";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
try {
FileIOHelper helper = new FileIOHelper(this,NAME,PATH );
String string = "Hello to Gryphone!";
helper.wrire(string);
byte[] array = helper.read(0, helper.length());
赞助商链接