當前位置:首頁 » 安卓系統 » 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();
}
}

熱點內容
資料庫5 發布:2025-02-08 21:43:17 瀏覽:51
安卓安裝證書沒有怎麼辦 發布:2025-02-08 21:32:10 瀏覽:358
外交官拉桿箱怎麼設密碼 發布:2025-02-08 21:21:55 瀏覽:797
vivo手機z系列哪個配置性價比最高 發布:2025-02-08 21:17:43 瀏覽:10
什麼是白標和伺服器 發布:2025-02-08 21:15:50 瀏覽:481
租完伺服器怎麼搭建ip 發布:2025-02-08 21:11:47 瀏覽:394
c語言賦值後 發布:2025-02-08 21:08:40 瀏覽:757
dosphp 發布:2025-02-08 21:01:27 瀏覽:703
sm3雜湊演算法 發布:2025-02-08 20:55:00 瀏覽:286
抽獎源碼帶後台 發布:2025-02-08 20:33:54 瀏覽:226