Josh Hartigan
Josh Hartigan

Reputation: 11

Struggling with making an HTML Editor in Java

I'm trying to create a totally simple, no-gui HTML editor in Java. What I've done is created a 'for' loop in which a string, namely 'str', is entered by the user, and is printed into the [name].html file (the name has been previously decided by the user), so long as 'str' does not equal 'quit', in which case the program ends. Here's the code, excluding the really simple naming part:

public static void edit(String nameParam) throws FileNotFoundException {

    //Creates the [name].html file
    PrintStream write = new PrintStream(new File(nameParam + ".html"));

    //puts the Name of the file at the top of the screen
    s.pl(nameParam);

    for(String str=scan.next(); !str.equalsIgnoreCase("quit");){
        s.p("~");
        write.println(str);
    }



}

However, it doesn't seem to be working. When I use the program, it lets me type whatever I want on however many lines, but doesn't print the '~' symbols at the beginning of the lines, and doesn't write them to the file (it does, however, create the file.). When I force-quit the program - there is no internal way to shut it down, although there should be - it prints an eternal line of ~ symbols.

Any help? Thanks.

EDIT: s.p == System.print; s.pl == System.println

Upvotes: 0

Views: 96

Answers (1)

Ben VonDerHaar
Ben VonDerHaar

Reputation: 281

Like other streams in java, you need to flush() after writing to the stream and close() when finished with the stream:

for (String str=scan.next(); !str.equalsIgnoreCase("quit");) {
    s.p("~");
    write.println(str);
    write.flush();
}

//...

write.close();

Upvotes: 1

Related Questions