Package util

Source Code of util.BatchLoader

package util;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import entity.ImageItem;

/*
* loads a bunch of items to db from a file: initial_load
* initial_load is a comma-delimited file, with pipe-delimited sub-fields (ex. tag array attribute)
* each row represents an Item object
*/
public class BatchLoader {
 
  public BatchLoader() {
  }

  public BatchLoader(String _filename) {
    BufferedReader br = null;
    try {
      br = new BufferedReader(new FileReader(_filename));
      String line = null;
      String[] itemData = null;
      while ((line = br.readLine()) != null) {
        itemData = line.split(",");
        ImageItem anItem = new ImageItem(itemData[0],itemData[1]);
        anItem.save();
        }     
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }  
  }
}
TOP

Related Classes of util.BatchLoader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.