`

android write file

阅读更多
	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代码-LogToFile

    2: Use FileLogUtils.write (your Log information); Log File Path: If the SD card or external memory exists, the SD Android data package name files Log logs.txt If there is an SD card or ex

    Android_file_manager

    file manager that you can read write in android root file structure.

    Caused by: android.system.ErrnoException: write failed: ENOSPC (

    Caused by: android.system.ErrnoException: write failed: ENOSPC (No space lef

    Linux驱动开发 file_operations ioctl read write驱动及Android应用程序调用

    资源含Android应用程序->JNI->C语言层->驱动...关键是file_operations!! 通过Android应用程序,能够控制GPIO LED,写入数据,以及去读已写入的数据。 Android应用程序中有两个BUTTON用不上,无关紧要,这就不删掉了。

    android 上传文件

    android 上传文件 progressBar.setMax((int)file.length()); String sourceid = fileService.find(file); Socket socket = new Socket("192.168.1.157", 7878); OutputStream outStream = socket....

    Android代码-RetroTextEditor

    It is a simple text file editor for Android. You can use it via a file manager app. I use it to write some notes. The fixed default file path is Documents/click.dummer.textthing/notes.txt . If you ...

    demo_write_file.zip_Android SD卡_DEMO_读写SD卡

    android环境下,sd卡读写的源代码。

    android 串口驱动

    /* Missing read/write permission, trying to chmod the file */ Process su; su = Runtime.getRuntime().exec("/system/bin/su"); /*String cmd = "chmod 777 " + device.getAbsolutePath() + "\n...

    phonegap 配置文件(android+eclipse+phonegap(cordova)配置项目 .)

    5.4把 setContentView() line with super.loadUrl(“file:///android_asset/www/index.html”); 6. 打开AndroidManifest.xml,拷贝 <supports-screens android:largeScreens="true" android:normalScreens="true...

    Android代码-CacheUtilsLibrary

    This is a simple Android utils library to write any type of data into cache files and then read them later, using Gson to serialize and deserialize these data. 中文版请看这里。 Gradle compile '...

    Android AudioRecorder录制mp3文件

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 在SDCard中创建与删除文件权限 <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />

    Android代码-Log4a 是一个基于 mmap, 高性能、高可用的 Android 日志收集框架

    Log4a (English | 中文) Log4a is an mmap based, high-performance, highly available Android log collection framework ...the log data will not be lost, and will write back to the log file at the next

    Beginning Android Games

    This will give you everything you need to branch out and write your own Android games. The potential user base and the wide array of available high-performance devices makes Android an attractive ...

    一个简单的开源Android工具类库

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android....

    android 调用相机显示拍摄后的图片

    对于拍摄照片我们可以直接调用系统自带的相机拍照,一般情况下无需...<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.CAMERA"/>

    8.1 android 串口编程

    allow system_app serial_device:chr_file { open read write ioctl getattr }; allow system_app proc_stat:file { getattr }; 这样那些自己驱动里创建的设备节点也就可以访问了。 然后mmm sepolicy。 串口的操作...

    opencv_android开发库

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 解压压缩包opencv231_Android.rar 拷贝openvc-2.3.1.jar和两个文件夹armeabi和armeabi-v7a到android项目的libs目录下 在oncreate...

    Android Security- Attacks and Defenses

    They also cover the Android file system, including import directories and files, so readers can perform basic forensic analysis on file system and SD cards. The book includes access to a wealth of ...

    Android Platform Developer‘s Guide.doc

    3. Write Drivers 38 4. Burn Images to Flash 39 5. Boot the kernel and mount the RAMdisk. 39 6. Debug Android-specific init programs on RAMdisk 39 7. Verify that applications have started 40 8. Pulling...

    Android调用相机并将照片显示出来

    Android调用相机并将照片显示出来,使用的是...<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />

Global site tag (gtag.js) - Google Analytics