导航:首页 > 操作系统 > 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文件相关的资料

热点内容
阿里云国际版试用的服务器怎么搞 浏览:889
java正则表达式工具 浏览:156
oa服务器怎么设置ftp 浏览:6
安卓如何安装obb 浏览:440
QQ聊天记录journal文件夹 浏览:118
苹果公司云服务器地址 浏览:85
加密记事本手机 浏览:437
汽车压缩机变频阀 浏览:95
域外服务器是什么意思 浏览:639
大众点评服务器怎么老卡顿 浏览:556
javavector与list的区别 浏览:316
java初始化类数组 浏览:303
java字符串转换成json对象 浏览:647
android非阻塞socket 浏览:358
编译系统概念 浏览:452
天眼通app能做什么 浏览:557
魅族手机怎么加密图库 浏览:8
rpa编译器 浏览:572
车载云服务器记录 浏览:740
四川金星压缩机制造有限公司 浏览:55