When I was reading the file today, I suddenly thought about how to read the file if it is stored in the raw directory?
Note that files from resources and assets can only be read but cannot be written.
Read from raw files as follows:
Code
Public String getfromraw (){
Try {
Inputstreamreader inputreader = New Inputstreamreader (getresources (). openrawresource (R. Raw. test1 ));
Bufferedreader bufreader = New Bufferedreader (inputreader );
String line = "" ;
String result = "" ;
While (Line = Bufreader. Readline ()) ! = Null )
Result + = Line;
Return Result;
} Catch (Exception e ){
E. printstacktrace ();
}
}
Read from assets directly
Code
Public String getfromassets (string filename ){
Try {
Inputstreamreader inputreader = New Inputstreamreader (getresources (). getassets (). Open (filename ));
Bufferedreader bufreader = New Bufferedreader (inputreader );
String line = "" ;
String result = "" ;
While (Line = Bufreader. Readline ()) ! = Null )
Result + = Line;
Return Result;
} Catch (Exception e ){
E. printstacktrace ();
}
}
Of course, if you want to get the memory stream, you can also directly return the memory stream!