Oct 30, 2013

android(java) 파일 저장 후 리부팅 시 저장안되어 있는 현상

android에서 FileOutputStream 의 write();,  flush(); 했는데도 리부팅 시 간헐적으로 파일이 생성되지 않았거나 파일 내 데이터가 변하지 않을 때가 있다.

FileOutputStream 의 flush(); 가 버퍼를 비우는 기능만 수행하고 실제 physical device에 데이터를 저장하지 않아 파일에 데이터를 쓰기까지의 딜레이가 생기는 것이다.

이 때 fos.getFD().sync();의 메서드로 파일시스템 내부의 캐쉬를 모두 physical device로 저장한다.



FileOutputStream fos = this.openFileOutput(filename, Context.MODE_PRIVATE);
fos.write(obj.toString().getBytes());
fos.flush();
fos.getFD().sync();
fos.close();

Oct 7, 2013

Shuffle 기능


 List< Integer > numbers;
Collections.shuffle( numbers );

// 0부터 6번째 인덱스 데이터 가지고 옴
        List< Integer > winningCombination = numbers.subList( 0 , 6 );

// 정렬
Collections.sort( winningCombination );