导航:首页 > 操作系统 > android写txt文件

android写txt文件

发布时间:2022-07-19 02:49:04

android 在手机中创建了txt文件,却无法写入数据,是为什么

你是说不能编辑吧!在手机上下载一个文本编辑器,例如WPS OFFICE,下载安装完成后,点击进入首页。进入后点下方的”+“号,点击后就会弹出一个下拉框,选择新建文档,点击后就会进入新建文档模式,进入后点上面的”新建空白,点入后就会弹出编辑页面,编辑好的文档传输给电脑用WORD和WPS都能打开。

② Android 根目录下读写.txt文件

java">//根目录权限不允许,放到/data/packeg_dir下或SD卡中

packagecom.example.demo;

Filedir=Environment.getDataDirectory();//获取data目录
//Environment.getExternalStorageDirectory();//获取SD卡目录
FileoutFile=newFile(dir,"/data/com.example.demo/text.txt");//只能在自己的程序包里建立文件,这是权限问题

③ Android开发问一下现在7.0怎么写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中

④ 求android 创建 txt 文件

  1. 打开手机助手

  2. 搜索txt编辑

  3. 安装就可以

  4. 然后运行,就可以新建,打开txt文件。

  5. 也可以所有office的word新建。这个系统自带。

⑤ 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文件

可以安装920文本编辑器,可以很方便创建文本文件

⑦ 你好,请问在android里面怎么新建TXT文件呢

你可以是用一些移动办公软件,这样就可以像电脑一样新建了。

⑧ Android能直接编辑TXT文档吗

luyongfeng是的,Andriod系统毕竟比Windows Mobile系统差一些。Andriod强在界面美观,便于用手指操作。而windows mobile系统接近于电脑的使用,象windows Xp一样。功能确实是强大的。比如这个TXt文本编辑,在Windows mobile系统中是小菜一碟,在Andriod系统中就会有麻烦,主要就是乱码问题。 还有一个看图软件,Andriod系统也是极为弱智。急盼改进。

⑨ android 如何读写文件

读文件:

1、通过File获取文件

2、打开输入流,读取文件

写文件:

1、创建文件

2、打开输出流,写入文件内容


示例:

读文件:
Stringcontent="";//文件内容字符串
//通过路径/sdcard/foo.txt打开文件
Filefile=newFile("/sdcard/foo.txt");
try{
InputStreaminstream=newFileInputStream(file);//读取输入流
InputStreamReaderinputreader=newInputStreamReader(instream);//设置流读取方式
BufferedReaderbuffreader=newBufferedReader(inputreader);
while((line=buffreader.readLine())!=null){
content+=line+" ";//读取的文件内容
}
}catch(Exceptionex){
}
写文件:
Filefile=newFile("/sdcard/foo.txt");//
if(!file.exists())
file.createNewFile();//如果文件不存在,创建foo.txt
try{
OutputStreamoutstream=newFileOutputStream(file);//设置输出流
OutputStreamWriterout=newOutputStreamWriter(outstream);//设置内容输出方式
out.write("文字内容");//输出内容到文件中
out.close();
}catch(java.io.IOExceptione){
e.printStackTrace();
}

⑩ 在android创建一个.txt文件怎么样写文件路径

filename = getSDPath() + "/" + formatter.format(currentTime) + ".txt";
filename = getSDPath() + "/" + getSystemTime();/////////////
file =new File(filename);
fileOutputStream = new FileOutputStream(file, true);

阅读全文

与android写txt文件相关的资料

热点内容
客户端框架源码 浏览:206
python自动办公能干嘛 浏览:873
程序员追爱 浏览:252
程序员逻辑故事 浏览:768
加密icsot23i2c 浏览:713
你们有什么好的解压软件 浏览:607
常州空气压缩机厂家 浏览:241
安卓如何关闭app内弹出的更新提示 浏览:409
e4a写的app怎么装苹果手机 浏览:201
海立压缩机海信系 浏览:210
社保如何在app上合并 浏览:220
小米加密照片后缀 浏览:236
我的世界网易手机怎么创服务器 浏览:978
载入单页源码 浏览:930
阿里云服务器seo 浏览:777
海洋斗什么时候上线安卓 浏览:86
中行app如何查每日汇款限额 浏览:840
输入服务器sn是什么意思 浏览:725
sha1算法java 浏览:90
asp代码压缩 浏览:851