Determine if the file exists:
/*** Determine if the file exists * *@parampath File Paths *@return[parameter description] *@returnBoolean [Return type description]*/ Public Static Booleanisfileexist (String path) {if(Textutils.isempty (path)) {return false; } File File=NewFile (path); returnfile.exists (); }
To determine whether a file exists, you need to generate a file object instance based on the path of the files and determine the existence of the file that the instance points to.
Reads the contents of the file (with one line as the specified information) and returns the ArrayList instance:
/*** < function description > read the specified directory resource file to return each line of data in the file as ArrayList * *@paramFileName *@return[parameter description] *@returnlist<string> [Return type description]*/ Public StaticList<string>readtxtfile (String fileName) {List<String> arrayList =NewArraylist<string>(); InputStream InputStream=NULL; BufferedReader BufferedReader=NULL; String TempStr=NULL; Try{File File=NewFile (fileName); InputStream=Newfileinputstream (file); BufferedReader=NewBufferedReader (NewInputStreamReader (InputStream,"Utf-8")); } Catch(IOException IOException) {LOGUTIL.D (TAG,"Readtxtfile::ioexception:" +ioexception.getmessage ()); } if(BufferedReader = =NULL) { returnarrayList; } Try{tempstr=Bufferedreader.readline (); while(TempStr! =NULL) {LOGUTIL.D (TAG,"Tmpstr=" +tempstr); Arraylist.add (Tempstr.trim ()); TempStr=Bufferedreader.readline (); } inputstream.close (); Bufferedreader.close (); } Catch(Exception Exception) {LOGUTIL.D (TAG,"Readtxtfile::exception" +exception.getmessage ()); } LOGUTIL.D (TAG,"Arraylist.length=" +arraylist.size ()); returnarrayList; }
(File operations) Android-related file operation