'sdcard 에 file 저장하기'에 해당되는 글 1건

  1. 2010.05.04 sdcard 에 file 저장하기
04.Anddoid2010. 5. 4. 14:13
반응형
java Source

 package lowmans.MySdcardWriteTest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MySdcardWriteTest extends Activity {
	
	final String tag = "MySdcardWriteTest";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        String path ="/sdcard/";
        File file = new File(path+"myTest.txt");
        try{
        	FileOutputStream fos = new FileOutputStream(file);
        	fos.write("this is test~!!\nThis Is Test~!!".getBytes());
        	fos.close();
        }catch(IOException e){
        	Log.i(tag , e.getMessage());
        }
    }
}

androidManifest.xml 에 use-permission 추가

 <?xml version="1.0" encoding="utf-8"?>
<manifest package="lowmans.MySdcardWriteTest"
      android:versionCode="1"
      android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">
    <application android:icon="@drawable/icon" android:label="@string/app_name"
    >
        <activity android:name=".MySdcardWriteTest"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="4" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
	
</manifest> 


출처 : http://www.androidpub.com/?mid=android_dev_info&category=108970&document_srl=253486
Posted by 1010