Android handheld PDA reads SD card files

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.