Package utils

Examples of utils.WriteToFile


     * This method removes all information from the text file that
     * saves the scores. Then it closes and reloads the window.
     */
    private void clearAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearAllButtonActionPerformed
        try {
            WriteToFile writer = new WriteToFile();
            String path = "scores.txt";
            String[] writeData = {""};
            writer.truncateAndWriteFile("scores.txt", writeData);
            Highscores highscores = new Highscores();
            highscores.setVisible(true);
            this.dispose();
           
        } catch (Exception ex) {
View Full Code Here


               
        try {
            String path = "dictionary.txt";
            String[] writeData = {newWord};
            System.out.println("writeData.length " + writeData.length);
            WriteToFile writer = new WriteToFile();
            writer.appendFile(path, writeData);
            return true;
           
        } catch(Exception e) {
           
            System.out.println("caught exception in service");
View Full Code Here

     * This array is then sent to the WriteToFile class, where the dictionary
     * file is truncated and rewritten.
     */
    public boolean removeWord(String word) {
        ReadFile reader = new ReadFile();
        WriteToFile writer = new WriteToFile();
        ArrayList<String> allWords = new ArrayList<String>();
        boolean wordRemoved = false;
        String path = "dictionary.txt";
       
        allWords = reader.readFromFile(path);
        allWords.removeAll(Collections.singleton(null));
       
       
        System.out.println("old size: " + allWords.size());
       
        for(int i = 0; i < (allWords.size() - 1); i++) {
           
            if(word.equals(allWords.get(i))) {
                allWords.remove(i);
                wordRemoved = true;
            }
        }
       
       
        allWords.removeAll(Collections.singleton(null));
        String[] toBeWritten = new String[allWords.size()];
       
        for (int j = 0; j < allWords.size(); j++) {
            System.out.println(allWords.get(j));
            toBeWritten[j] = allWords.get(j);
        }
       
        System.out.println("tobewritten: " + toBeWritten.length);
        System.out.println("New size: " + allWords.size());
       
        for (int k = 0; k < toBeWritten.length; k++) {
            System.out.println("toBeWritten: " + toBeWritten[k]);
        }
       
        try {
            writer.truncateAndWriteFile("dictionary.txt", toBeWritten);
       
        } catch(Exception e) {
            System.out.println("Error: " + e);
        }       
       
View Full Code Here

TOP

Related Classes of utils.WriteToFile

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.