10MB 파일(File) 생성하여 내부저장소(Storage)에 쓰기(Write)
MainActivity.java
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 29 30 31 32 33 34 35 36 37 | //버튼 public void mOnFileWriteClick(View v){ FileWrite(); } //파일쓰기 public void FileWrite(){ //File 디렉토리 , File명 String dirPath = Environment.getExternalStorageDirectory()+"/Blog"; String filename = "TestFile10MB.temp"; //디렉토리 없으면 생성 File dir = new File(dirPath); if(!dir.exists()){ dir.mkdir(); } //파일객체 File file = new File(dir, filename); try{ //쓰기객체 FileOutputStream fos = new FileOutputStream(file); //버퍼 - 1MB씩쓰기 byte[] buffer = new byte[1*1024*1024]; for(int i=0; i<10; i++){ //10MB fos.write(buffer, 0, buffer.length); //1MB씩 10번쓰기 fos.flush(); } int len = 0; fos.close(); Toast.makeText(this, "File Write Success", Toast.LENGTH_SHORT).show(); }catch (IOException e){ e.printStackTrace(); } } | cs |
AndroidManifest.xml
1 2 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | cs |
내부저장소(Storage)에 쓰기권한
결과
'IT > - 프로그래밍' 카테고리의 다른 글
안드로이드 타이틀바 없애기 (0) | 2016.08.04 |
---|---|
안드로이드 사진파일을 갤러리에 추가하기 (0) | 2016.08.04 |
안드로이드 Properties 파일 읽기, 쓰기 : Properties File Read/Write In Android (0) | 2016.07.30 |
안드로이드 접근성 화면으로 이동하기 : Accessibility Settings (0) | 2016.07.30 |
안드로이드 화면 캡쳐하기 : Screen Capture In Android (1) | 2016.07.30 |