HTML generation & writing

Discussion in 'Spigot Plugin Development' started by OLLIE-Z4, Sep 3, 2017.

Thread Status:
Not open for further replies.
  1. How would I generate a HTML file and then write to it? My question is as small as that, I can't find anywhere to get started and have been unable to figure it out myself

    PS: The plugin needs to make the file
     
  2. Code (Java):
    File file = new File(this.getDataFolder(), "index.html");

    public void createFile() {
      YamlConfiguration config = YamlConfiguration.loadConfiguration(this.file);
      // Check if the file already exists, if not create the file with
      file.createNewFile();
    }
     
    • Like Like x 1
    • Funny Funny x 1
  3. I'm sure you know how to create a file and write to it, if you want a good way to generate HTML code programatically you should look into something like j2html.

    If you can't create the file in the first place I would recommend some Java tutorials.
     
    • Like Like x 1
  4. That's not what I meant. I know how to create the file, my struggle is writing to it. For example if I use:

    Code (Text):

            YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
            config.set("<p>hi</p>", "");
     
    (I don't know any other way around it)

    I get the result:

    Code (Text):

    <p>hi</p>: ''
     
    Where as I need:

    Code (Text):

    <p>hi</p>
     
     
  5. Use a FileWriter.
     
    • Like Like x 1
  6. Don't use YamlConfiguration for a HTML file. There are some streams out there, like FileOutputStream.
     
    • Winner Winner x 1
    • Like Like x 1
  7. Alright thank you, I got it, Ended up using what @ersterstreber said xP
     
Thread Status:
Not open for further replies.