導航:首頁 > 操作系統 > android保存txt文件

android保存txt文件

發布時間:2022-09-23 18:18:27

android 能不能以制定的編碼格式保存txt

可以,android的是基於java語言的 你可以設置OutputStreamWriter的編碼格式new java.io.OutputStreamWriter(out,"gb2312") 然後將輸出流寫到txt文件里就可以了

Ⅱ 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(); } }

Ⅲ android開發,如何在sdcard上保存自定義名稱的txt文件,需要完整能運行的代碼,謝謝啦大神們

private void write(String content){
String FILE_NAME = "XX.txt";
//如果手機插入SD卡,而且程序有訪問SD許可權
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
//獲取SD卡目錄
File sdCardDir = Environment.getExternalStorageDirectory();
try {
File targetFile = new File(sdCardDir.getCanonicalPath()+FILE_NAME);
RandomAccessFile raf = new RandomAccessFile(targetFile, "rw");
raf.seek(targetFile.length());//文件記錄指針移到最後
raf.write(content.getBytes());
raf.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}
不要忘了在manifest里添加SD卡寫入許可權:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Ⅳ 開發的android程序需要把收集到的數據存入txt文件,這些文件沒有root許可權似乎看不到,該怎麼上傳到電腦上

跟root沒啥關系
能讀到message的話就說明不是root
你看你是否有在manifest.xml裡面添加寫入SD卡的許可權
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Ⅳ Android寫入txt文件

分以下幾個步驟:

  1. 首先對manifest注冊SD卡讀寫許可權

    AndroidManifest.xml
    <?xmlversion="1.0"encoding="utf-8"?>
    <manifestxmlns:android="

    package="com.tes.textsd"
    android:versionCode="1"
    android:versionName="1.0">
    <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16"/>
    <uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity
    android:name="com.tes.textsd.FileOperateActivity"
    android:label="@string/app_name">
    <intent-filter>
    <actionandroid:name="android.intent.action.MAIN"/>
    <categoryandroid:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    </activity>
    </application>
    </manifest>
  2. 創建一個對SD卡中文件讀寫的類

    FileHelper.java
    /**
    *@Title:FileHelper.java
    *@Packagecom.tes.textsd
    *@Description:TODO(用一句話描述該文件做什麼)
    *@authorAlex.Z
    *@date2013-2-26下午5:45:40
    *@versionV1.0
    */
    packagecom.tes.textsd;
    importjava.io.DataOutputStream;
    importjava.io.File;
    importjava.io.FileOutputStream;
    importjava.io.FileWriter;
    importjava.io.FileInputStream;
    importjava.io.FileNotFoundException;
    importjava.io.IOException;
    importandroid.content.Context;
    importandroid.os.Environment;
    publicclassFileHelper{
    privateContextcontext;
    /**SD卡是否存在**/
    privatebooleanhasSD=false;
    /**SD卡的路徑**/
    privateStringSDPATH;
    /**當前程序包的路徑**/
    privateStringFILESPATH;
    publicFileHelper(Contextcontext){
    this.context=context;
    hasSD=Environment.getExternalStorageState().equals(
    android.os.Environment.MEDIA_MOUNTED);
    SDPATH=Environment.getExternalStorageDirectory().getPath();
    FILESPATH=this.context.getFilesDir().getPath();
    }
    /**
    *在SD卡上創建文件
    *
    *@throwsIOException
    */
    publicFilecreateSDFile(StringfileName)throwsIOException{
    Filefile=newFile(SDPATH+"//"+fileName);
    if(!file.exists()){
    file.createNewFile();
    }
    returnfile;
    }
    /**
    *刪除SD卡上的文件
    *
    *@paramfileName
    */
    publicbooleandeleteSDFile(StringfileName){
    Filefile=newFile(SDPATH+"//"+fileName);
    if(file==null||!file.exists()||file.isDirectory())
    returnfalse;
    returnfile.delete();
    }
    /**
    *寫入內容到SD卡中的txt文本中
    *str為內容
    */
    publicvoidwriteSDFile(Stringstr,StringfileName)
    {
    try{
    FileWriterfw=newFileWriter(SDPATH+"//"+fileName);
    Filef=newFile(SDPATH+"//"+fileName);
    fw.write(str);
    FileOutputStreamos=newFileOutputStream(f);
    DataOutputStreamout=newDataOutputStream(os);
    out.writeShort(2);
    out.writeUTF("");
    System.out.println(out);
    fw.flush();
    fw.close();
    System.out.println(fw);
    }catch(Exceptione){
    }
    }
    /**
    *讀取SD卡中文本文件
    *
    *@paramfileName
    *@return
    */
    publicStringreadSDFile(StringfileName){
    StringBuffersb=newStringBuffer();
    Filefile=newFile(SDPATH+"//"+fileName);
    try{
    FileInputStreamfis=newFileInputStream(file);
    intc;
    while((c=fis.read())!=-1){
    sb.append((char)c);
    }
    fis.close();
    }catch(FileNotFoundExceptione){
    e.printStackTrace();
    }catch(IOExceptione){
    e.printStackTrace();
    }
    returnsb.toString();
    }
    publicStringgetFILESPATH(){
    returnFILESPATH;
    }
    publicStringgetSDPATH(){
    returnSDPATH;
    }
    publicbooleanhasSD(){
    returnhasSD;
    }
    }
  3. 寫一個用於檢測讀寫功能的的布局

    main.xml
    <?xmlversion="1.0"encoding="utf-8"?>
    <LinearLayoutxmlns:android="

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <TextView
    android:id="@+id/hasSDTextView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="hello"/>
    <TextView
    android:id="@+id/SDPathTextView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="hello"/>
    <TextView
    android:id="@+id/FILESpathTextView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="hello"/>
    <TextView
    android:id="@+id/createFileTextView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="false"/>
    <TextView
    android:id="@+id/readFileTextView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="false"/>
    <TextView
    android:id="@+id/deleteFileTextView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="false"/>
    </LinearLayout>
  4. 就是UI的類了

    FileOperateActivity.class
    /**
    *@Title:FileOperateActivity.java
    *@Packagecom.tes.textsd
    *@Description:TODO(用一句話描述該文件做什麼)
    *@authorAlex.Z
    *@date2013-2-26下午5:47:28
    *@versionV1.0
    */
    packagecom.tes.textsd;
    importjava.io.IOException;
    importandroid.app.Activity;
    importandroid.os.Bundle;
    importandroid.widget.TextView;
    {
    privateTextViewhasSDTextView;
    privateTextViewSDPathTextView;
    ;
    ;
    ;
    ;
    privateFileHelperhelper;
    @Override
    publicvoidonCreate(BundlesavedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    hasSDTextView=(TextView)findViewById(R.id.hasSDTextView);
    SDPathTextView=(TextView)findViewById(R.id.SDPathTextView);
    FILESpathTextView=(TextView)findViewById(R.id.FILESpathTextView);
    createFileTextView=(TextView)findViewById(R.id.createFileTextView);
    readFileTextView=(TextView)findViewById(R.id.readFileTextView);
    deleteFileTextView=(TextView)findViewById(R.id.deleteFileTextView);
    helper=newFileHelper(getApplicationContext());
    hasSDTextView.setText("SD卡是否存在:"+helper.hasSD());
    SDPathTextView.setText("SD卡路徑:"+helper.getSDPATH());
    FILESpathTextView.setText("包路徑:"+helper.getFILESPATH());
    try{
    createFileTextView.setText("創建文件:"
    +helper.createSDFile("test.txt").getAbsolutePath());
    }catch(IOExceptione){
    e.printStackTrace();
    }
    deleteFileTextView.setText("刪除文件是否成功:"
    +helper.deleteSDFile("xx.txt"));
    helper.writeSDFile("1213212","test.txt");
    readFileTextView.setText("讀取文件:"+helper.readSDFile("test.txt"));
    }
    }

Ⅵ android開發中,做一個了注冊的界面後,如何將注冊的信息以TXT文件形式保存在SD卡中

你需要在xml文件裡面使能外部的sd卡:
<!-- 在SDCard中創建於刪除文件的許可權 -->
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<!-- 往SDCard中寫入數據的許可權 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

然後android的java code如下:
public void saveToSDCard(String filename,String content) throws Exception{
File file=new File(Environment.getExternalStorageDirectory(), filename);
OutputStream out=new FileOutputStream(file);
out.write(content.getBytes());
out.close();
}

Ⅶ 安卓手機有什麼軟體可以把網頁保存為TXT文件

8.7版本可以,方法是打開一下網頁,拖動屏幕下方UC菜單欄,點擊啟動語音功能,說出「保存網頁」,即可選擇保存為純文本格式文件。但是8.8以後的版本都沒有此功能了.目前保存網頁的格式都是HTML的

Ⅷ android系統中,可否保存和修改txt文件

可以的 需要第三方軟體。再有一個就是像root explorer這種文件管理器也是可以通過root許可權授予,可以修改體統程序的txt文件 更改一些低級別文件重寫。

閱讀全文

與android保存txt文件相關的資料

熱點內容
ai文件pdf 瀏覽:909
騰訊雲伺服器掛載混合雲 瀏覽:758
智能小車用什麼單片機 瀏覽:463
java怎麼給窗口關閉 瀏覽:940
列舉51單片機的定址方式 瀏覽:706
剪輯app怎麼寫長篇文字 瀏覽:400
app專屬流量過月租怎麼不更新 瀏覽:654
王者程序員都有誰 瀏覽:76
給牛換腳掌解壓 瀏覽:387
圍棋有多少種演算法 瀏覽:602
unity資源包在哪個文件夾 瀏覽:704
阿里雲伺服器遠程鏈接不成功 瀏覽:482
文件系統pdf 瀏覽:766
原神安卓區服什麼意思 瀏覽:37
貝殼app怎麼線上發布 瀏覽:159
如何挑選安卓系統機頂盒 瀏覽:54
安卓快充使用有什麼注意事項 瀏覽:909
黑馬程序員的雲計算網課 瀏覽:947
endnotestyle文件夾怎麼導入 瀏覽:460
講解少兒編程演講會開頭 瀏覽:426