In the last two years, many wince devices on the market have started to turn to the Android operating system and have recently been forced to use Android to develop PDA handheld devices. The main functions are scanning login, picking, packing, shipping several functions. It involves to the product file when about 700 of goods to import into the Android device, because the field operating environment does not have WiFi, so the product can not directly access the service, the product record into the TXT file.
I. Store the TXT file in SD Open
Edit the product file into a TXT file and then copy to the SD card, of course, you can also store other data formats, and even use SQLite to store, there is no need to use the TXT directly
Two. Set access rights
Configure the appropriate access rights in Androidmanifest.xml
<uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/><uses-permission android: Name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
Three. Accessing directory issues
Directories in the Android system are different from those of the Windows system, starting with the "/" root directory. The following is the code to read the TXT file
arraylist<string> list = new arraylist<string> (); if (Environment.getexternalstoragestate (). Equals ( environment.media_mounted) {try {file File=new file ("/sdcard/products.txt"), if (!file.exists ()) { file.mkdir (); } InputStreamReader Read = new InputStreamReader (new FileInputStream (file), "UTF-8"); BufferedReader br = new BufferedReader (read); String str = null;while ((str = Br.readline ())! = null) {list.add (str);}} catch (Exception e) {e.printstacktrace ();}}
where file File=new file ("/sdcard/products.txt"); is the path to access the file, it is important to note that the SD is open to "/sdcard"
Android handheld PDA reads SD card files