Java API reads all files in the HDFs directory

Source: Internet
Author: User

/** * Get the 1th store fresh food Classification ID String * @param filePath * @return */public string getyhdsxcategoryidstr (String FilePath) {final string D Elimiter = new string (new Byte[]{1}), final string inner_delimiter = ",";//Traverse All files under directory BufferedReader br = null;try {Filesys TEM fs = Filesystem.get (new Configuration ()); filestatus[] Status = Fs.liststatus (new Path (FilePath)), for (Filestatus file:status) {if (!file.getpath (). GetName (). StartsWith ("part-")) {continue;} Fsdatainputstream InputStream = Fs.open (File.getpath ()); br = new BufferedReader (new InputStreamReader (InputStream)); String line = Null;while (null! = (line = Br.readline ())) {string[] STRs = Line.split (DELIMITER); String categoryId = strs[0]; String categorysearchname = strs[9];if ( -1! = Categorysearchname.indexof ("0-956955")) {yhdsxcategoryidstr + = ( CategoryId + Inner_delimiter);}} End of While}} catch (IOException e) {e.printstacktrace ();} finally {try {br.close ()} catch (IOException e) {e.printst Acktrace ();}} return YHDSXCATEGORYIDSTR;}


directories, files on HDFs:

-bash-3.2$ Hadoop fs-ls/user/hive/warehouse/categoryfound 2 items-rw-r--r--   2 basicdata supergroup          0 2014-08-18 01:05/user/hive/warehouse/category/_success-rw-r--r--   2 basicdata supergroup    1117233 2014-08-18 01:05/user/hive/warehouse/category/part-m-00000

File Contents:

-bash-3.2$ Hadoop fs-cat/user/hive/warehouse/category/part-* | more52880000052880 Cereal Combination 51621010-5135-5162-5288: food-cereals and oils-cereals combination 0119726780009726787 Tea Set 19650290040-950340-965029-972678: Home-tableware with water-tea set 10119701550009701557 Fiskan 196046510null0-960464-960465-970155: contact lenses (drug net)- GENERAL contact lenses-Fiskan 10119702350009702356 Life service 000180-970235: Life Service 0119702360009702367SIM Card 9635241030-957328-963524-970236: Mobile Communications/Digital Appliances-carrier-sim card 0119737840009737842 shoe bag Accessories 97377810null0-960665-960768-973775-973778-973784 : Gift Center 1th-Fashion Creative gifts-bespoke products-personalized-shoes bag accessories 0115315t602 Personal Cleaning 5183190null0-5134-5183-5315: Kitchen cleaning-cleaners-Personal cleaning 1115316t603 household cleaning 5183190null0-5134-5183-5316: Kitchen cleaning-cleaners-household cleaning 1115317ud02 Egg products 1516110null0-5135-5161-5317 : Food and beverage-pickled products 1-egg products 11115318ud030 meat 5161180null0-5135-5161-5318: Food and beverage-pickled products-meat products 111

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.