android 是否是文件,如何检查android中是否存在txt文件

我想要的是一段代码的和平,它检查文本文件是否存在。我正在使用java。如何检查android中是否存在txt文件

我要的是这样的:

if (the file.txt exists) { do a action } else {do another action }

的文件是在应用程序的数据文件夹中的文件目录。谢谢! :P

编辑:我保存这样的文件:

public class crear_data_mes {

String nArchivo_mes = "mes.txt";

Context ctx_mes;

FileOutputStream fos_mes;

FileInputStream fis_mes;

public crear_data_mes(Context ctx) {

this.ctx_mes=ctx;

}

public void escribir_mes(String textoarchivo_mes) {

try {

fos_mes= ctx_mes.openFileOutput(nArchivo_mes, Context.MODE_PRIVATE);

fos_mes.write(textoarchivo_mes.getBytes());

fos_mes.close();

} catch (FileNotFoundException e) {

Log.e("Hola", "Hola" + e.getMessage());

} catch (IOException ex) {

Log.e("Hola", "Hola"+ex.getMessage());

}

}

public String leer_mes() {

String lectura_mes = "";

try {

fis_mes = ctx_mes.openFileInput(nArchivo_mes);

int i;

int n_mes = 0;

char caracter_mes='a';

do {

i = fis_mes.read();

if (i!='\n') {

caracter_mes = (char)i;

lectura_mes=lectura_mes+caracter_mes;

}

} while (i>0);

lectura_mes+="\n";

} catch (Exception e) { }

return lectura_mes;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值