Package java.io

Examples of java.io.File


      PrintStream... progress)
    throws Exception {
   
    // check to see if this is a KnowledgeFlow package (presence of Beans.props file)
    if (updateKnowledgeFlow) {
      File packageToDel = new File(PACKAGE_MANAGER.getPackageHome().toString() + File.separator
          + packageName);
      if (packageToDel.exists() && packageToDel.isDirectory()) {
        File[] contents = packageToDel.listFiles();
        for (int i = 0; i < contents.length; i++) {
          if (contents[i].isFile() && contents[i].getPath().endsWith("Beans.props")) {
            // KnowledgeFlow plugin -- remove this properties file from the list of
            // bean plugin props
View Full Code Here


   */
  public void addUndoPoint() throws Exception {
   
    if (m_Instances != null) {
      // create temporary file
      File tempFile = File.createTempFile("weka", SerializedInstancesLoader.FILE_EXTENSION);
      tempFile.deleteOnExit();

      ObjectOutputStream oos =
  new ObjectOutputStream(
  new BufferedOutputStream(
  new FileOutputStream(tempFile)));
View Full Code Here

   * Saves the currently selected clusterer
   */
  protected void saveClusterer(String name, Clusterer clusterer,
             Instances trainHeader, int[] ignoredAtts) {

    File sFile = null;
    boolean saveOK = true;

    int returnVal = m_FileChooser.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      sFile = m_FileChooser.getSelectedFile();
      if (!sFile.getName().toLowerCase().endsWith(MODEL_FILE_EXTENSION)) {
  sFile = new File(sFile.getParent(), sFile.getName()
       + MODEL_FILE_EXTENSION);
      }
      m_Log.statusMessage("Saving model to file...");
     
      try {
  OutputStream os = new FileOutputStream(sFile);
  if (sFile.getName().endsWith(".gz")) {
    os = new GZIPOutputStream(os);
  }
  ObjectOutputStream objectOutputStream = new ObjectOutputStream(os);
  objectOutputStream.writeObject(clusterer);
  if (trainHeader != null) objectOutputStream.writeObject(trainHeader);
  if (ignoredAtts != null) objectOutputStream.writeObject(ignoredAtts);
  objectOutputStream.flush();
  objectOutputStream.close();
      } catch (Exception e) {
 
  JOptionPane.showMessageDialog(null, e, "Save Failed",
              JOptionPane.ERROR_MESSAGE);
  saveOK = false;
      }
      if (saveOK)
  m_Log.logMessage("Saved model (" + name
       + ") to file '" + sFile.getName() + "'");
      m_Log.statusMessage("OK");
    }
  }
View Full Code Here

   */
  protected void loadClusterer() {

    int returnVal = m_FileChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File selected = m_FileChooser.getSelectedFile();
      Clusterer clusterer = null;
      Instances trainHeader = null;
      int[] ignoredAtts = null;

      m_Log.statusMessage("Loading model from file...");

      try {
  InputStream is = new FileInputStream(selected);
  if (selected.getName().endsWith(".gz")) {
    is = new GZIPInputStream(is);
  }
  ObjectInputStream objectInputStream = new ObjectInputStream(is);
  clusterer = (Clusterer) objectInputStream.readObject();
  try { // see if we can load the header & ignored attribute info
    trainHeader = (Instances) objectInputStream.readObject();
    ignoredAtts = (int[]) objectInputStream.readObject();
  } catch (Exception e) {} // don't fuss if we can't
  objectInputStream.close();
      } catch (Exception e) {
 
  JOptionPane.showMessageDialog(null, e, "Load Failed",
              JOptionPane.ERROR_MESSAGE);
     

      m_Log.statusMessage("OK");
     
      if (clusterer != null) {
  m_Log.logMessage("Loaded model from file '" + selected.getName()+ "'");
  String name = (new SimpleDateFormat("HH:mm:ss - ")).format(new Date());
  String cname = clusterer.getClass().getName();
  if (cname.startsWith("weka.clusterers."))
    cname = cname.substring("weka.clusterers.".length());
  name += cname + " from file '" + selected.getName() + "'";
  StringBuffer outBuff = new StringBuffer();

  outBuff.append("=== Model information ===\n\n");
  outBuff.append("Filename:     " + selected.getName() + "\n");
  outBuff.append("Scheme:       " + clusterer.getClass().getName());
  if (clusterer instanceof OptionHandler) {
    String [] o = ((OptionHandler) clusterer).getOptions();
    outBuff.append(" " + Utils.joinOptions(o));
  }
View Full Code Here

  public void setOptions(String[] options) throws Exception {
    setDebug(Utils.getFlag("D", options));
   
    setOutputFilename(Utils.getFlag("F", options));
   
    setDirectory(new File(Utils.getOption("dir", options)));
   
    String charSet = Utils.getOption("charset", options);
    m_charSet = "";
    if (charSet.length() > 0) {
      m_charSet = charSet;
View Full Code Here

   * get the Dir specified as the source
   *
   * @return     the source directory
   */
  public File getDirectory() {
    return new File(m_sourceFile.getAbsolutePath());
  }
View Full Code Here

    if (m_structure == null) {
      String directoryPath = getDirectory().getAbsolutePath();
      ArrayList<Attribute> atts = new ArrayList<Attribute>();
      ArrayList<String> classes = new ArrayList<String>();
     
      File dir = new File(directoryPath);
      String[] subdirs = dir.list();
     
      for (int i = 0; i < subdirs.length; i++) {
  File subdir = new File(directoryPath + File.separator + subdirs[i]);
  if (subdir.isDirectory())
    classes.add(subdirs[i]);
      }
     
      atts.add(new Attribute("text", (ArrayList<String>) null));
      if (m_OutputFilename)
View Full Code Here

   
    Instances data = getStructure();
    int fileCount = 0;
    for (int k = 0; k < classes.size(); k++) {
      String subdirPath = (String) classes.get(k);
      File subdir = new File(directoryPath + File.separator + subdirPath);
      String[] files = subdir.list();
      for (int j = 0; j < files.length; j++) {
  try {
    fileCount++;
    if (getDebug())
      System.err.println(
    "processing " + fileCount + " : " + subdirPath + " : " + files[j]);
   
    double[] newInst = null;
    if (m_OutputFilename)
      newInst = new double[3];
    else
      newInst = new double[2];       
    File txt = new File(directoryPath + File.separator + subdirPath + File.separator + files[j]);
    BufferedReader is;
    if (m_charSet == null || m_charSet.length() == 0) {
      is = new BufferedReader(new InputStreamReader(new FileInputStream(txt)));
    } else {
      is = new BufferedReader(new InputStreamReader(new FileInputStream(txt), m_charSet));
View Full Code Here

   */
  public void setOptions(String[] options) throws Exception {
   
    String demandDir = Utils.getOption('D', options);
    if (demandDir.length() != 0) {
      setOnDemandDirectory(new File(demandDir));
    }

    super.setOptions(options);
  }
View Full Code Here

  public void setOnDemandDirectory(File newDir) {

    if (newDir.isDirectory()) {
      m_OnDemandDirectory = newDir;
    } else {
      m_OnDemandDirectory = new File(newDir.getParent());
    }
  }
View Full Code Here

TOP

Related Classes of java.io.File

Copyright © 2018 www.massapicom. 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.