티스토리 뷰

Manifest.xml 에 권한 추가
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

====== DB파일, 파일위치 : mnt/sdcard/파일명.db 였던듯 (이클립스의 DDMS/File Explorer 기준)
String st r= Environment.getExternalStorageDirectory().getAbsolutePath();
SQLiteDatabase _db = openOrCreateDatabase(str + "/jusoList.db", SQLiteDatabase.CREATE_IF_NECESSARY , null);

====== 일반파일, 파일위치 : mnt/sdcard/Diary/파일명
  String SDCardPATH = Environment.getExternalStorageDirectory().getAbsolutePath();
  File file = new File(SDCardPATH, fileName);
  String text = "안녕하세요";
  FileOutputStream fos = null;
  try{
   file.createNewFile();
   fos = new FileOutputStream(file.getAbsolutePath());
   fos.write(text.getBytes());
   fos.close();
  }
  catch(IOException e){
   Log.e("ReadWriteSDCardFile.LOGTAG", "ERROR", e);
  }
        /*
        File rFile = new File(fileName);
        if(rFile.exists() && rFile.canRead()){
         FileInputStream fis = null;
         try{
          fis = new FileInputStream(rFile);
          byte[] reader = new byte[fis.available()];
          while(fis.read(reader) != -1){}
          Toast.makeText(FileTest.this, reader.toString(), Toast.LENGTH_SHORT).show();
         }
         catch(IOException e){}
         finally{
          if(fis != null){
           try{
            fis.close();
           }
           catch(IOException e){}
          }
         }
        }
        else
         Toast.makeText(FileTest.this, "SDCard 읽기오류", Toast.LENGTH_SHORT).show();
        */
  if(file.exists()){
   try{
    FileInputStream fis = new FileInputStream(file.getAbsolutePath());
    long fileSizeInByte = file.length();
    byte[] bytes = new byte[(int)fileSizeInByte];
    fis.read(bytes);
    fis.close();
    Toast.makeText(FileTest.this, new String(bytes), Toast.LENGTH_SHORT).show();
   }
   catch(IOException e){
    e.printStackTrace();
   }
  }
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28