2012年12月7日 星期五

在BroadcastReceiver內使用Internal Storage I/O


//Read in. st. from File"screenoff"
        String fileName = "screenoff";
        int readed;
        String content="";
        byte[] buff = new byte[256]; //input stream buffer
        //Input stream
        try{
        FileInputStream reader = context.getApplicationContext().openFileInput(fileName);
        while((readed = reader.read(buff))!=-1){
         content+=new String(buff).trim();
        }
        }catch(FileNotFoundException e){
        e.printStackTrace();
        }catch (IOException e){
        e.printStackTrace();
        }
        //End of Read in. st. from File"screenoff"

----------------------------------------------------------------------------------------------------
Instead of openFileInput("string.txt"); try usingcontext.getApplicationContext().openFileInput("string.txt");.

沒有留言:

張貼留言

Related Posts Plugin for WordPress, Blogger...