当前位置:首页 > 开发 > 移动开发 > 正文

android write file

发表于: 2014-12-29   作者:andyxrl   来源:转载   浏览次数:
摘要: public static void writefile(String text, String fileName){ File externalStorageDir = Environment.getExternalStorageDirectory(); File myFile = new File(externalStorageDir , fileName);//fi
	public static void writefile(String text, String fileName){
		File externalStorageDir = Environment.getExternalStorageDirectory();
        File myFile = new File(externalStorageDir , fileName);//fileName: 1.txt
        if(myFile.exists())
        {
           try
           {
	        FileOutputStream fostream = new FileOutputStream(myFile);
	        OutputStreamWriter oswriter = new OutputStreamWriter(fostream); 
	        BufferedWriter bwriter = new BufferedWriter(oswriter);   
	        bwriter.write(text);
	        bwriter.newLine();            
	        bwriter.close(); 
	        oswriter.close(); 
	        fostream.close();
           }
	        catch (IOException e)
	        {
	            e.printStackTrace();
	        }
        }
        else
        {
            try {
                myFile.createNewFile();
            }
            catch (IOException e) 
            {
                e.printStackTrace();
            }
        }
    }

 

android write file

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
昨天再做android的3D图360度全景图时,从 http://code.google.com/p/panoramagl-android/downloads/
昨天再做android的3D图360度全景图时,从 http://code.google.com/p/panoramagl-android/downloads/
昨天再做android的3D图360度全景图时,从 http://code.google.com/p/panoramagl-android/downloads/
Read / Write Excel file in Java using Apache POI 2014-04-18 BY DINESH LEAVE A COMMENT About a
package com.file.properties; import java.io.File; import java.io.FileNotFoundException; impor
问题如下: 'Setting build path' has encountered a problem.Could not write file: D:\MyCode\act
最近要将列表写入文件里面,但是不能带列表的中括号,在我之前的那篇Erlang模式匹配列表的深入理解
1、 在Android的java层实现文件的读写操作是非常简单的 在JNI层实现文件的读写操作的话,就要使用到l
数据的存储有多种方式,比如数据库存储、SharedPreferences存储、文件存储等; 这里我们将要介绍最
res/layout/row.xml <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="h
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号