当前位置:首页 » 安卓系统 » android读文本

android读文本

发布时间: 2023-06-06 18:24:59

① android 开发怎么读取并显示txt文件

StringBuffer sb = new StringBuffer(); File file = new File("myfile.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String line = ""; while((line = br.readLine())!=null){ sb.append(line); } br.close(); (TextView)findViewById(R.id.text1).setText(sb.toString()); 第二行,创建文件对象,指向需要读取的文件 第三行,创建文件Reader对象,读取指定的文件 第四五行,创建一个line接受读取的文件内容,因为是文本文件,所以一行一行读 第八行,关闭文件读取对象 第九行,将文本文件内容写入到TextVIew中

安卓系统的手机用什么阅读软件可以直接看WORD的文本

wpsoffice,步骤如下:


1、首先在手机上进行下载并安装wpsoffice软件,完成后,点击即可打开进入新的界面。


③ android怎样读文本文件的内容

1. 读取操作
String path = "/sdcard/foo.txt";
String content = ""; //文件内容字符串
//打开文件
File file = new File(path);
//如果path是传递过来的参数,可以做一个非目录的判断
if (file.isDirectory()){
Toast.makeText(EasyNote.this, "没有指定文本文件!", 1000).show();
}
else{
try {
InputStream instream = new FileInputStream(file);
if (instream != null) {
InputStreamReader inputreader = new InputStreamReader(instream);
BufferedReader buffreader = new BufferedReader(inputreader);
String line;
//分行读取
while (( line = buffreader.readLine()) != null) {
content += line + "\n";
}
instream.close();
} catch (java.io.FileNotFoundException e) {
Toast.makeText(EasyNote.this, "文件不存在", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
2. 写入操作
String filePath = "/sdcard/foo2.txt";
String content = "这是将要写入到文本文件的内容";
//如果filePath是传递过来的参数,可以做一个后缀名称判断; 没有指定的文件名没有后缀,则自动保存为.txt格式
if(!filePath.endsWith(".txt") && !filePath.endsWith(".log"))
filePath += ".txt";
//保存文件
File file = new File(filePath);
try {
OutputStream outstream = new FileOutputStream(file);
OutputStreamWriter out = new OutputStreamWriter(outstream);
out.write(content);
out.close();
} catch (java.io.IOException e) {
e.printStackTrace();
}

④ Android对于读文本文件到底使用什么读取格式

要做到自动识别,你必须有一个方法来识别文本编码才行。

⑤ 安卓怎样可以像iPhone一样选中文本朗读

你可以选择任何文字内容,来让iPhone朗读出来,未开启VoiceOver也可以。步骤如下:
(1)在主屏幕上找到“设置”图标并打开它。
(2)在设置列表下,轻按“通用”按钮。
(3)在通用列表下,轻按“辅助功能”按钮。
(4)在“视觉”选项卡下,轻按“朗读所选项”按钮,进入设置。
(5)轻按打开“朗读所选项”开关。
(6)你可以选择调节“朗读速率”的大小。
(7)在信息当中,你可以选中信息内容,然后轻按“朗读”,即可把收到的信息读出来。编者按:
使用iPhone朗读所选项的功能,当打开的状态下,你可以选中信息、邮件、备忘录、提醒事项等文本的内容,然后iPhone会自动朗读。

⑥ 什么软件在安卓手机能打开txt文件

电子书软件,wps手机版都可以打开TXT文件,操作方法如下:

1、首先在手机上找到并打开WPS。

⑦ android一个文本文件如何按行读取

try{
InputStreammyInput=mcontext.getResources().openRawResource(R.raw.medicalspeciality);
InputStreamReaderreader=newInputStreamReader(myInput);
BufferedReaderbreader=newBufferedReader(reader);
Stringstr;
FileWritermyOutput=newFileWriter(outFileName,true);
while((str=breader.readLine())!=null){
System.out.println(i+++str);
}
//Closethestreams
myOutput.flush();
myOutput.close();
myInput.close();
}catch(Exceptione){
//TODO:handleexception
e.getStackTrace();
}

⑧ android如何读取txt文本里面的数据

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String fileName = "/sdcard/y.txt";//文件路径
// 也可以用String fileName = "mnt/sdcard/Y.txt";
String res = "";
try {
FileInputStream fin = new FileInputStream(fileName);
// FileInputStream fin = openFileInput(fileName);
// 用这个就不行了,必须用FileInputStream
int length = fin.available();
byte[] buffer = new byte[length];
fin.read(buffer);
res = EncodingUtils.getString(buffer, "UTF-8");////依Y.txt的编码类型选择合适的编码,如果不调整会乱码
fin.close();//关闭资源
System.out.println("res--->"+res);
int a=Integer.parseInt(res.substring(3, 5));
int b=Integer.parseInt(res.substring(8, 10));
System.out.println(a+"res--->"+b);//获取的a.b
} catch (Exception e) {
e.printStackTrace();
}
}

热点内容
英国访问学者签证费用 发布:2025-02-08 23:04:46 浏览:926
洛奇合成脚本 发布:2025-02-08 22:57:04 浏览:141
linux文件软链接 发布:2025-02-08 22:35:48 浏览:773
iphone6s缓存怎么清理 发布:2025-02-08 22:33:17 浏览:928
数据库系统设计的步骤 发布:2025-02-08 22:11:19 浏览:44
processc语言 发布:2025-02-08 22:11:15 浏览:537
国产车配置为什么这么便宜 发布:2025-02-08 22:09:52 浏览:481
服务器为什么需要专线 发布:2025-02-08 22:07:27 浏览:872
java正则表达式正则替换 发布:2025-02-08 22:01:04 浏览:506
服务器不识别配置的ip地址 发布:2025-02-08 22:00:02 浏览:615