Exemplo n.º 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...");
   }
   // }
 }
Exemplo n.º 2
0
  /**
   * Create/Replace a File
   *
   * @param Direct the Directory in which the File is made
   * @param Txt the Text to be written in the file
   */
  public void createFile(String Direct, String Txt) {
    File f = new File(Direct + File_Name);

    if (f.isFile()) { // Check if this file already exists
      if (JOptionPane.showConfirmDialog(
              null, "This file already exists, do you wish to replace it?", "Replace", 0)
          != 0) {
        return;
      }
      // Delete file
      f.delete();
    }

    try {
      // Replace/Create file
      f.createNewFile();
      // If file preference set to "File with displayed text", write text to file
      if (Txt != null) {
        WriteFile(f, Txt);
      }
      Msgs.Type("File created", Display);
    } catch (Exception e) {
      Msgs.Type("Unable to create this file", Display);
    }
  }
Exemplo n.º 3
0
  void doExeCommand() {
    JViewport viewport = scrollPane.getViewport();
    String strContent = new String();
    PSlider slider;
    int i;
    File fp = new File(dataFile);

    RandomAccessFile access = null;
    Runtime program = Runtime.getRuntime();
    String cmdTrigger = "trigger";

    boolean delete = fp.delete();

    try {
      fp.createNewFile();
    } catch (IOException ie) {
      System.err.println("Couldn't create the new file " + ie);
      // System.exit(-1);;
    }

    try {
      access = new RandomAccessFile(fp, "rw");
    } catch (IOException ie) {
      System.err.println("Error in accessing the file " + ie);
      // System.exit(-1);;
    }

    for (i = 0; i < COMPONENTS; i++) {
      slider = (PSlider) vSlider.elementAt(i);
      /* Modified on March 20th to satisfy advisors' new request */
      if (slider.isString == true) strContent = strContent + slider.getRealStringValue() + " ";
      else strContent = strContent + slider.getValue() + " ";
    }

    // Get value of the radio button group
    if (firstBox.isSelected() == true) strContent = strContent + "1";
    else strContent = strContent + "0";

    try {
      access.writeBytes(strContent);
      access.close();
    } catch (IOException ie) {
      System.err.println("Error in writing to file " + ie);
      // System.exit(-1);;
    }
    // Trigger the OpenGL program to update with new values
    try {
      Process pid = program.exec(cmdTrigger);
    } catch (IOException ie) {
      System.err.println("Couldn't run " + ie);
      // System.exit(-1);;
    }
    doSourceFileUpdate();
  }
 private static List<String> readLinesFrom(File file) throws IOException {
   if (!file.exists()) file.createNewFile();
   ArrayList<String> result = new ArrayList<>();
   BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
   try {
     String line;
     while ((line = reader.readLine()) != null) result.add(line);
     return result;
   } finally {
     reader.close();
   }
 }
Exemplo n.º 5
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();
   }
 }
Exemplo n.º 6
0
 public FileManager(String user, String database) {
   pathToFile =
       System.getProperty("user.home")
           + File.separator
           + "AppData"
           + File.separator
           + "Local"
           + File.separator
           + "DBAdmin";
   userFile = new File(pathToFile + File.separator + user + "_" + database + ".dat");
   if (!userFile.exists()) {
     try {
       userFile.createNewFile();
     } catch (IOException e) {
       JOptionPane.showMessageDialog(
           LogInFrame.getInstance(),
           "Could not save user data!",
           "Error",
           JOptionPane.ERROR_MESSAGE);
       e.printStackTrace();
     }
   }
 }
Exemplo n.º 7
0
 /**
  * This function writes the generated relative overview to a file.
  *
  * @param f The file to write to.
  * @throws IOException Thrown if unable to open or write to the file.
  * @throws InsufficientDataException Thrown if unable to generate the overview.
  */
 public void writeToFile(File f) throws IOException, InsufficientDataException {
   f.createNewFile();
   FileWriter fw = new FileWriter(f);
   fw.write(generateOverviewText());
   fw.close();
 }
Exemplo n.º 8
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // TODO code application logic here
    hilos = new HashMap<String, Thread>();
    StringTokenizer token = new StringTokenizer(OS, " ");
    OS = token.nextToken().toLowerCase();
    token = null;
    if (OS.equals("windows")) {
      // Creamos las variables
      StringBuilder path = new StringBuilder(System.getProperty("user.home")); // Path del sistema
      path.append("\\AppData\\Roaming\\Data"); // Agregamos los datos
      String name = "data.cfg", booleano = "boolean.txt"; // Nombre de ficheros de datos
      String pss = "My Pass Phrase"; // Nombre de frase pass
      String boo = path.toString() + "\\" + booleano; // Path del fichero booleano
      File fich = new File(path.toString());
      fich.mkdirs();
      path.append("\\").append(name);
      File fichero = new File(boo);
      // Controlamos si es la primera vez que se ejecuta y si hay registro o no
      if (fichero.exists()) {
        try {
          // Leemos el fichero si existe
          BufferedReader bf = new BufferedReader(new FileReader(fichero));
          boo = bf.readLine();
        } catch (IOException e) {

        }
        if (boo.equals("true")) {
          // Si en el fichero hay un true, significa que ya se ha registrado y abrimos la Vista2
          Vista2 vista = new Vista2(pss);
          vista.setIconImage(
              new ImageIcon(
                      System.getProperty("user.home") + "\\AppData\\Roaming\\.minecraft\\5547.png")
                  .getImage());
          vista.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          vista.setTitle(title + " " + version);
          vista.setLocationRelativeTo(null);
          vista.setVisible(true);
          vista.pack();
        } else {
          // Sino, no se ha registrado, y abrimos la Vista
          Vista.main(path.toString(), pss, fichero.getAbsolutePath());
        }
      } else {
        // Si no existe el fichero, lo creamos y escribimos en él false
        try {
          fichero.createNewFile();
          PrintWriter pw = new PrintWriter(fichero);
          pw.print("false");
          pw.close();
        } catch (IOException e) {

        }
        // Abrimos Vista
        Vista.main(path.toString(), pss, fichero.getAbsolutePath());
      }
    } else if (OS.equals("linux")) {
      // Creamos las variables
      StringBuilder path = new StringBuilder(System.getProperty("user.home")); // Path del sistema
      path.append("/Data"); // Agregamos los datos
      String name = "data.cfg", booleano = "boolean.txt"; // Nombre de ficheros de datos
      String pss = "My Pass Phrase"; // Nombre de frase pass
      String boo = path.toString() + "/" + booleano; // Path del fichero booleano
      File fich = new File(path.toString());
      fich.mkdirs();
      path.append("/").append(name);
      File fichero = new File(boo);
      // Controlamos si es la primera vez que se ejecuta y si hay registro o no
      if (fichero.exists()) {
        try {
          // Leemos el fichero si existe
          BufferedReader bf = new BufferedReader(new FileReader(fichero));
          boo = bf.readLine();
        } catch (IOException e) {

        }
        if (boo.equals("true")) {
          // Si en el fichero hay un true, significa que ya se ha registrado y abrimos la Vista2
          Vista2 vista = new Vista2(pss);
          vista.setIconImage(
              new ImageIcon(System.getProperty("user.home") + "/.minecraft/5547.png").getImage());
          vista.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          vista.setTitle(title + " " + version);
          vista.setLocationRelativeTo(null);
          vista.setVisible(true);
          vista.pack();
        } else {
          // Sino, no se ha registrado, y abrimos la Vista
          Vista.main(path.toString(), pss, fichero.getAbsolutePath());
        }
      } else {
        // Si no existe el fichero, lo creamos y escribimos en él false
        try {
          fichero.createNewFile();
          PrintWriter pw = new PrintWriter(fichero);
          pw.print("false");
          pw.close();
        } catch (IOException e) {

        }
        // Abrimos Vista
        Vista.main(path.toString(), pss, fichero.getAbsolutePath());
      }
    }
  }
Exemplo n.º 9
0
  void doSourceFileUpdate() {
    BufferedReader bufferIn = null;
    String str1 = new String();
    String strContent = new String();
    String sliderValue = new String();
    String newLine = System.getProperty("line.separator");
    StringBuffer strBuf = new StringBuffer();
    RandomAccessFile access = null;
    String tempFile = "temp" + round + ".html";
    File fp = new File(tempFile);
    boolean firstChoice = true;
    int posFound = 0;
    int i = 0;
    PSlider slider;

    // round += 1;
    // Read the original source file to input buffer
    try {
      bufferIn = new BufferedReader(new FileReader(exampleSource));
    } catch (FileNotFoundException fe) {
      System.err.println("Example Source File not found " + fe);
      // System.exit(-1);;
    }
    // get the first line of the buffer.
    try {
      str1 = bufferIn.readLine();
    } catch (IOException ie) {
      System.err.println("Error reading line from the buffer " + ie);
      // System.exit(-1);;
    }
    // Transfer the whole content of the input buffer to the string
    try {
      do strContent += str1 + newLine;
      while ((str1 = bufferIn.readLine()) != null);
    } catch (IOException ie) {
      System.err.println("Error readding content of the input buffer " + ie);
      // System.exit(-1);;
    }
    // do the replacement.
    // First having to update the code part that is active in this section before
    // doing variables updated. Look at the current active radiobutton to make decision
    if (secondBox.isSelected() == true) firstChoice = false;
    if (firstChoice == true) {
      String tempStr = new String();
      strBuf = new StringBuffer(strContent);
      posFound = strContent.indexOf(textStr2);
      tempStr =
          "<font color=blue>/***********" + newLine + textStr2 + newLine + "***********/</font>";
      strBuf.replace(posFound, posFound + textStr2.length(), tempStr);
      strContent = new String(strBuf);
    } else {
      String tempStr = new String();
      strBuf = new StringBuffer(strContent);
      posFound = strContent.indexOf(textStr1);
      tempStr =
          "<font color=blue>/***********" + newLine + textStr1 + newLine + "***********/</font>";
      strBuf.replace(posFound, posFound + textStr1.length(), tempStr);
      strContent = new String(strBuf);
    }
    for (i = COMPONENTS; i > 0; i--) {
      // get the current value of slider
      slider = (PSlider) vSlider.elementAt(i - 1);
      sliderValue = slider.getValue();
      // construct the search string
      str1 = "JPOT$" + i;
      // get the position of the search string in the content string.
      while ((posFound = strContent.indexOf(str1)) != -1) {
        strBuf = new StringBuffer(strContent);
        strBuf.replace(posFound, posFound + str1.length(), sliderValue);
        strContent = new String(strBuf);
      }
    }

    boolean delete = fp.delete();

    try {
      fp.createNewFile();
    } catch (IOException ie) {
      System.err.println("Couldn't create the new file " + ie);
      // System.exit(-1);;
    }

    try {
      access = new RandomAccessFile(fp, "rw");
    } catch (IOException ie) {
      System.err.println("Error in accessing the file " + ie);
      // System.exit(-1);;
    }

    try {
      access.writeBytes(strContent);
      access.close();
    } catch (IOException ie) {
      System.err.println("Error in writing to file " + ie);
      // System.exit(-1);;
    }
    try {
      textPane.getDocument().putProperty(Document.StreamDescriptionProperty, null);
      URL url = new URL("file:" + tempFile + "#gohere");
      textPane.setPage(url);
      delete = fp.delete();
    } catch (IOException ie) {
      System.err.println("Can not get the example html file " + ie);
      // System.exit(-1);;
    }
  }