예제 #1
0
 private void saveTab(String toSave, File f) {
   boolean ok = false;
   BufferedWriter out = null;
   try {
     ok = f.createNewFile();
   } catch (IOException e) {
     e.printStackTrace();
   }
   if (ok) {
     try {
       out = new BufferedWriter(new FileWriter(f));
       out.write(toSave);
     } catch (IOException e1) {
       e1.printStackTrace();
     } finally {
       try {
         out.close();
       } catch (IOException e2) {
         e2.printStackTrace();
       }
     }
   } else {
     System.out.println("Couldnt create file...");
   }
   // }
 }
예제 #2
0
 @FXML
 private void handleExportItemAction(ActionEvent event) {
   try {
     BufferedWriter bw =
         new BufferedWriter(
             new OutputStreamWriter(new FileOutputStream("imageInformation.csv"), "UTF-8"));
     for (ImageInformation img : imgMan.images) {
       StringBuffer oneLine = new StringBuffer();
       oneLine.append(img.getPath());
       oneLine.append(";");
       for (Point p : img.getPoints()) {
         oneLine.append(p.getX() + "," + p.getY());
       }
       oneLine.append(";");
       for (ImageInformation.Type t : img.getTypes()) {
         oneLine.append(t.toString());
       }
       oneLine.append(";");
       for (double d : img.getFrequency()) {
         oneLine.append(d + ",");
       }
       oneLine.append(";");
       bw.write(oneLine.toString());
       bw.newLine();
     }
     bw.flush();
     bw.close();
   } catch (UnsupportedEncodingException e) {
   } catch (FileNotFoundException e) {
   } catch (IOException e) {
   }
 }
예제 #3
0
파일: Installer.java 프로젝트: suever/CTP
 private void setFileText(File file, String text) throws Exception {
   BufferedWriter bw =
       new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
   bw.write(text, 0, text.length());
   bw.flush();
   bw.close();
 }
예제 #4
0
  public void save() {
    BufferedWriter sourceFile = null;

    try {
      String sourceText = sourceArea.getText();

      String cleanText = cleanupSource(sourceText);

      if (cleanText.length() != sourceText.length()) {
        sourceArea.setText(cleanText);

        String message =
            String.format(
                "One or more invalid characters at the end of the source file have been removed.");
        JOptionPane.showMessageDialog(this, message, "ROPE", JOptionPane.INFORMATION_MESSAGE);
      }

      sourceFile = new BufferedWriter(new FileWriter(sourcePath, false));
      sourceFile.write(cleanText);

      setSourceChanged(false);

      setupMenus();
    } catch (IOException ex) {
      ex.printStackTrace();
    } finally {
      if (sourceFile != null) {
        try {
          sourceFile.close();
        } catch (IOException ignore) {
        }
      }
    }
  }
예제 #5
0
 /**
  * Puts results into a HTML file.
  *
  * @param prefix
  * @param hits
  * @param reader
  * @param queryImage
  * @return
  * @throws IOException
  */
 public static String saveImageResultsToHtml(
     String prefix, TopDocs hits, IndexReader reader, String queryImage) throws IOException {
   long l = System.currentTimeMillis() / 1000;
   String fileName = "results-" + prefix + "-" + l + ".html";
   BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
   bw.write(
       "<html>\n"
           + "<head><title>Search Results</title></head>\n"
           + "<body bgcolor=\"#FFFFFF\">\n");
   bw.write("<h3>query</h3>\n");
   bw.write(
       "<a href=\"file://" + queryImage + "\"><img src=\"file://" + queryImage + "\"></a><p>\n");
   bw.write("<h3>results</h3>\n");
   for (int i = 0; i < hits.scoreDocs.length; i++) {
     bw.write(
         hits.scoreDocs[i].score
             + " - <a href=\"file://"
             + reader.document(hits.scoreDocs[i].doc).get("descriptorImageIdentifier")
             + "\"><img src=\"file://"
             + reader.document(hits.scoreDocs[i].doc).get("descriptorImageIdentifier")
             + "\"></a><p>\n");
   }
   bw.write("</body>\n" + "</html>");
   bw.close();
   return fileName;
 }
예제 #6
0
  public void write(OutputStream os) throws Exception {
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));

    String str = toString();
    bw.write(str, 0, str.length());
    bw.newLine();
    bw.close();
  }
  private void writeTree(GeneBranch tree, String dir) {
    try {
      BufferedWriter writer1 = new BufferedWriter(new FileWriter(dir + tree.gene + ".sif"));
      BufferedWriter writer2 = new BufferedWriter(new FileWriter(dir + tree.gene + ".format"));

      writer2.write("graph\tgrouping\ton\n");
      writer2.write("node\t" + tree.gene + "\tcolor\t255 255 200\n");

      writeBranches(tree.gene, tree, writer1, writer2);

      writer1.close();
      writer2.close();
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
예제 #8
0
    public static Settings init() throws Exception {
      File f = new File("galaxyviewer.ini");
      if (f.getAbsoluteFile().getParentFile().getName().equals("bin"))
        f = new File("..", "galaxyviewer.ini");
      Settings settings;
      if (f.exists()) {
        settings = new Settings();
        BufferedReader in = new BufferedReader(new FileReader(f));
        while (true) {
          String s = in.readLine();
          if (s == null) break;
          if (s.contains("=") == false) continue;
          String[] el = s.split("=", -1);
          if (el[0].equalsIgnoreCase("PlayerNr"))
            settings.playerNr = Integer.parseInt(el[1].trim()) - 1;
          if (el[0].equalsIgnoreCase("GameName")) settings.gameName = el[1].trim();
          if (el[0].equalsIgnoreCase("GameDir")) settings.directory = el[1].trim();
        }
        in.close();
      } else settings = new Settings();

      JTextField pNr = new JTextField("" + (settings.playerNr + 1));
      JTextField gName = new JTextField(settings.gameName);
      JTextField dir = new JTextField("" + settings.directory);

      JPanel p = new JPanel();
      p.setLayout(new GridLayout(3, 2));
      p.add(new JLabel("Player nr"));
      p.add(pNr);
      p.add(new JLabel("Game name"));
      p.add(gName);
      p.add(new JLabel("Game directory"));
      p.add(dir);
      gName.setToolTipText("Do not include file extensions");
      String[] el = {"Ok", "Cancel"};
      int ok =
          JOptionPane.showOptionDialog(
              null,
              p,
              "Choose settings",
              JOptionPane.OK_CANCEL_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              el,
              el[0]);
      if (ok != 0) System.exit(0);
      settings.playerNr = Integer.parseInt(pNr.getText().trim()) - 1;
      settings.directory = dir.getText().trim();
      settings.gameName = gName.getText().trim();
      BufferedWriter out = new BufferedWriter(new FileWriter(f));
      out.write("PlayerNr=" + (settings.playerNr + 1) + "\n");
      out.write("GameName=" + settings.gameName + "\n");
      out.write("GameDir=" + settings.directory + "\n");
      out.flush();
      out.close();
      return settings;
    }
예제 #9
0
 /**
  * When exiting the game, save the best score to the record file.
  *
  * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
  */
 @Override
 public void windowClosing(WindowEvent arg0) {
   try {
     recordWriter = new BufferedWriter(new FileWriter("res/record"));
     recordWriter.write(String.valueOf(bestScore));
     recordWriter.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
예제 #10
0
 /**
  * Writes the error model into the options file so that they can be read by the generator at a
  * later time
  */
 public void storeModelPreference(String model) {
   try {
     FileWriter x = new FileWriter("options", true);
     BufferedWriter optionWriter = new BufferedWriter(x);
     String data = "<IpErrorModel> " + model + " </IpErrorModel>\n";
     optionWriter.write(data, 0, data.length());
     optionWriter.flush();
     optionWriter.close();
   } catch (Exception e) {
     System.out.println("Error while writing to options file in ipModelsMenu.java");
   }
 }
예제 #11
0
    public void actionPerformed(ActionEvent ae) {

      if (ae.getActionCommand().equals("clear")) {
        scriptArea.setText("");
      } else if (ae.getActionCommand().equals("save")) {
        // fc.setCurrentDirectory(new File("/Users/jc/Documents/LOGO"));
        int bandera = fileChooser.showSaveDialog(myWindow);
        if (bandera == JFileChooser.APPROVE_OPTION) {
          String cadena1 = scriptArea.getText();
          String cadena2 = cadena1.replace("\r", "\n");
          System.out.println(cadena1);
          try {
            BufferedWriter script =
                new BufferedWriter(new FileWriter(fileChooser.getSelectedFile() + ".txt"));
            script.write(cadena2);
            script.close();
          } catch (Exception ex) {
            ex.printStackTrace();
          }
          File file = fileChooser.getSelectedFile();
          JOptionPane.showMessageDialog(myWindow, "File: " + file.getName() + " Saved.\n");
        }
        scriptArea.setCaretPosition(scriptArea.getDocument().getLength());
      } else if (ae.getActionCommand().equals("quit")) {
        myWindow.setVisible(false);
      } else if (ae.getActionCommand().equals("load")) {
        // String arreglo[] = new String[100];
        // int i = 0;
        // fc.setCurrentDirectory(new File("/Users/jc/Documents/LOGO"));
        int bandera = fileChooser.showOpenDialog(myWindow);
        if (bandera == JFileChooser.APPROVE_OPTION) {
          try {
            BufferedReader script =
                new BufferedReader(new FileReader(fileChooser.getSelectedFile()));
            scriptArea.read(script, null);
            script.close();
            scriptArea.requestFocus();
          } catch (Exception ex) {
            ex.printStackTrace();
          }
          File file = fileChooser.getSelectedFile();
          myWindow.setTitle(file.getName());
          JOptionPane.showMessageDialog(myWindow, file.getName() + ": File loaded.\n");
          scriptArea.setCaretPosition(scriptArea.getDocument().getLength());
        }
      } else if (ae.getActionCommand().equals("run")) {
        System.out.println("LEL");
      }
    }
예제 #12
0
파일: Main.java 프로젝트: joeytwiddle/code
 public void write() {
   filename = "open/" + filename;
   try {
     BufferedWriter br = new BufferedWriter(new FileWriter(new File(filename)));
     br.write(precode);
     for (int i = 0; i < classes.size(); i++) {
       System.out.println("Jooifying " + (i + 1) + " out of " + classes.size() + 1);
       br.write(((Class) classes.get(i)).toString());
     }
     br.close();
     System.out.println("Written file " + filename);
   } catch (Exception e) {
     System.out.println("Exception " + e + " occured");
   }
 }
예제 #13
0
 /** Safely disconnects this ClientHandler from the Server */
 public void disconnect() {
   try {
     pool.removeFromAllQueues(this);
     if (game != null) {
       game.endGame(false); // End the game the client was in.
     }
     reader.close();
     writer.close();
     client.close();
     System.out.println("[Server] Debug (ClientHandler) - Client has disconnected.");
     pool.removeClient(name);
     connected = false;
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
예제 #14
0
 public void save(String s, File f) {
   try {
     int saveNumber = 1;
     File file = new File(f.getAbsolutePath() + "/save.adv");
     while (file.exists()) {
       file = new File(f.getAbsolutePath() + "/save" + saveNumber + ".adv");
       saveNumber++;
     }
     file.createNewFile();
     FileWriter fWriter = new FileWriter(file.getAbsoluteFile());
     BufferedWriter bWriter = new BufferedWriter(fWriter);
     bWriter.write(s);
     bWriter.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
예제 #15
0
파일: Console.java 프로젝트: pavileanu/Luci
 public static void addDiskRefernce(String output) {
   BufferedWriter writer = null;
   try {
     // writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("log.txt")));
     writer = new BufferedWriter(new FileWriter("disks.txt", true));
     writer.write(output + "\n");
   } catch (IOException ex) {
     // report
   } finally {
     try {
       writer.close();
     } catch (Exception ex) {
         /*ignore*/
       ex.printStackTrace();
     }
   }
 }
  private void printVals(double[] vals1, double[] vals2, String symbol) {
    try {
      BufferedWriter writer = new BufferedWriter(new FileWriter("/home/ozgun/Desktop/temp.txt"));

      writer.write("Ras-mutated\tBRAF-mutated\n");
      for (int i = 0; i < Math.max(vals1.length, vals2.length); i++) {
        if (i < vals1.length) writer.write(vals1[i] + "");
        writer.write("\t");
        if (i < vals2.length) writer.write(vals2[i] + "");
        writer.write("\n");
      }
      writer.close();

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
예제 #17
0
파일: Vue.java 프로젝트: exidhor/Bejeweled
  public void ecrireFichier(String chemin, Vector<Integer> highScore) {
    try {
      FileWriter fw = new FileWriter(chemin, false);

      BufferedWriter output = new BufferedWriter(fw);

      for (int i = 0; i < highScore.size(); i++) {
        output.write(highScore.get(i).toString());
        output.newLine();
      }

      output.flush();

      output.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
예제 #18
0
  public void saveAs() {
    Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>();

    if (fileExt.equals("m") || fileExt.equals("mac")) {
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
    } else {
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
    }
    filters.add(new RopeFileFilter(new String[] {".txt"}, "Text files (*.txt)"));

    RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters);
    chooser.setDialogTitle("Save Source File");
    String fileName = String.format("%s.%s", baseName, fileExt);
    chooser.setSelectedFile(new File(selectedPath, fileName));
    JTextField field = chooser.getTextField();
    field.setSelectionStart(0);
    field.setSelectionEnd(baseName.length());
    File file = chooser.save(ROPE.mainFrame);
    if (file != null) {
      selectedPath = file.getParent();

      BufferedWriter writer = null;
      try {
        writer = new BufferedWriter(new FileWriter(file));
        writer.write(sourceArea.getText());
      } catch (IOException ex) {
        ex.printStackTrace();
      } finally {
        try {
          if (writer != null) {
            writer.close();
          }
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
  }
예제 #19
0
    public void run() {
      try {
        BufferedReader br =
            new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
        if (outputFile != null) {
          bw =
              new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), charset));
        }
        String line;
        while ((line = br.readLine()) != null) {
          filePosition += line.length() + 2;
          line = line.trim();
          if (!line.startsWith("#")) {
            String[] sides = split(line);
            if ((sides != null) && !sides[0].equals("key")) {

              if (searchPHI) {
                // Search the decrypted PHI for the searchText
                sides[0] = decrypt(sides[0]);
                if (sides[0].indexOf(searchText) != -1) {
                  output(sides[0] + " = " + sides[1] + "\n");
                }
              } else {
                // Search the trial ID for the searchText
                if (sides[1].indexOf(searchText) != -1) {
                  sides[0] = decrypt(sides[0]);
                  output(sides[0] + " = " + sides[1] + "\n");
                }
              }
            }
          }
        }
        br.close();
        if (bw != null) {
          bw.flush();
          bw.close();
        }
      } catch (Exception e) {
        append("\n\n" + e.getClass().getName() + ": " + e.getMessage() + "\n");
      }
      append("\nDone.\n");
      setMessage("Ready...");
    }
예제 #20
0
  public synchronized void runSuite() {
    SikuliIDE ide = SikuliIDE.getInstance();
    if (fRunner != null) {
      fTestResult.stop();
      showIDE(true);
    } else {
      try {
        showIDE(false);
        reset();

        // get the current file's python code, write it to a temp file, and run it
        File tmpFile = null;
        String className = null;
        SikuliCodePane codePane = ide.getCurrentCodePane();
        try {
          className = new File(ide.getCurrentFilename()).getName();
          className = className.substring(0, className.lastIndexOf('.')); // remove extension
          tmpFile = File.createTempFile(className, ".py");
          tmpFile.deleteOnExit();
          BufferedWriter bw =
              new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tmpFile), "UTF8"));
          codePane.writePython(bw);
          bw.close();
        } catch (IOException e) {
          e.printStackTrace();
          showIDE(true);
        }
        String filename = tmpFile.getAbsolutePath();

        String path = ide.getCurrentBundlePath();
        Test suite = genTestSuite(className, filename, path);
        doRun(suite);
      } catch (IOException e) {
        e.printStackTrace();
        showIDE(true);
      }
    }
  }
예제 #21
0
    public void actionPerformed(ActionEvent e) {
      double payRate, hours, basePay, overtimePay, overtimeHours, netPay;
      String payDate, name, hoursErr, outputStr;

      payDate = (dateTF.getText());
      name = (nameTF.getText());
      payRate = Double.parseDouble(payrateTF.getText().is);
      hours = Double.parseDouble(hoursworkedTF.getText());
      overtimeHours = Double.parseDouble(otworkedTF.getText());
      basePay = payRate * hours;
      overtimePay = (1.5 * payRate) * overtimeHours;
      netPay = basePay + overtimePay;

      // throw error if hours entered is more than 40
      if (hours > 40) {
        hoursErr =
            "Hours worked must be 40 or less. Please enter "
                + "the data again. Any additional time over 40 is considered"
                + " overtime.";

        JOptionPane.showMessageDialog(null, hoursErr, "Error", JOptionPane.ERROR_MESSAGE);
      }

      // or continue with output
      else {

        outputStr =
            "Regular Pay: $"
                + basePay
                + "\n"
                + "Overtime Pay: $"
                + overtimePay
                + "\n"
                + "Total Pay: $"
                + netPay
                + "\n\n"
                + "Summary available in the EmployeePayroll.txt file.";

        JOptionPane.showMessageDialog(
            null, outputStr, "Total Pay for " + name + ".", JOptionPane.INFORMATION_MESSAGE);
      }

      try {
        // Create text file, publish information, and close it.
        FileWriter fstream = new FileWriter("EmployeePayroll.txt", true);
        BufferedWriter out = new BufferedWriter(fstream);
        out.write("***Pay Calculation***\n");
        out.write("Pay Date: " + payDate + "\n");
        out.write("Employee Name: " + name + "\n");
        out.write("Pay Rate: " + payRate + "\n");
        out.write("Regular Hours: " + hours + "\n");
        out.write("Overtime Hours: " + overtimeHours + "\n");
        out.write("Regular Pay: $" + basePay + "\n");
        out.write("Overtime Pay: $" + overtimePay + "\n");
        out.write("Total Pay: $" + netPay + "\n");

        // Close the output stream
        out.close();
      } catch (Exception f) { // Catch exception if any
        System.err.println("Error: " + f.getMessage());
      }
    }