FileWriter does not write.

	public void parseSynonyms(String line, ArrayList<String> synonyms, File f){
		try{
			BufferedWriter fw = new BufferedWriter(new FileWriter(f));
			fw.newLine();
			
			Scanner scanner = new Scanner(line);
			scanner.useDelimiter(" ");
			
			while(scanner.hasNext()){
				String s = scanner.next();
				if (s.contains("[[")){
					if (Memory.get().isDebugMode()) {
						System.out.println(s);
					}
					fw.write(" " + s);
					fw.flush();
					fw.newLine();
					synonyms.add(s);
				}
			}
			
			fw.close();
		}catch(FileNotFoundException e){
			e.printStackTrace();
			System.out.println("Criticial Error, Exiting.");
			System.exit(0);
		}catch(IOException e){
			e.printStackTrace();
		}
	}

I can’t find anything wrong with this.
S does have a string in it. Not empty.
The file exists. In fact, the program creates it if it doesn’t.
It overwrites the file and empties it to add to insult.

How do I fix this?

You forget to close the Scanner…

Cheers :slight_smile:

Other than optimizing my program, that didn’t fix anything hahah.
Thanks anyway for helping and for reminding me of that though, hahah. :slight_smile:

Just tried it here and it works fine. The file is written for me (provided your passed line string does actually contain a “[[”, otherwise its empty).

Where do you write? If you tried to write on drive C on windows 7 with UAC enabled, there’s chance will fail.

I just write to the folder it’s in, which is in Documents/My Projects/Java Projects/Aida/

You know what’s awesome? When something doesn’t work on your computer but does on pretty much everyone elses.

Dammit Java. Even if I’m onto something, I’m not.

@ReBirth, you would get a FileNotFoundException if so.

@OP are you sure the strings contain “[[” in the first place?

Yup. It outputs before it supposedly writes.

I just said screw it and wrote it to a singleton hashtable and outputted the object through an object stream.

Java seriously pisses me of sometimes.

Off subject, I have another problem.

        for (int a = 1; a < words.size(); a++){
        	String word = words.get(a);
        	String word2 = words.get(a-1);
        	
        	if (word.equals(word2)){
        		words.remove(a);
        	}
        }

All words are “?”

It doesn’t remove them.
What am I doing wrong?

Well, it should remove half of them (I think).

Perhaps you meant something like this:


        for (int a = 1; a < words.size(); a++){
           String word = words.get(a);
           String word2 = words.get(a-1);
           
           if (word.equals(word2)){
              words.remove(a--);
           }
        }

Are you using UTF-8 to read the words, assuming that you are reading the words in at first.