Search code examples
javajava.util.scannerfilewriter

What is wrong with my Java .html file generator


I am working on an .html file generator that can be used to view .swf files in a browser, however I'm getting a "Unresolved compilation problem" error. Is there possibly a problem with my imports?

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class CreateFile {
    public static String starthtml = "<object><embed src=\"";
    public static String endhtml = ".swf\" width=\"100%\" height=\"100%\"></embed></object>";
    public static String s;
  public static void main(String[] args) {
    try {
      File myObj = new File("Flash Loader.html");
      if (myObj.createNewFile()) {
        System.out.println("Flash Loader Created Successfully");
      } else {
        System.out.println("File already exists");
      }
    } catch (IOException e) {
      System.out.println("An error occurred");
      e.printStackTrace();
    }
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter SWF file name");
    s = sc.nextLine();
    try {
        FileWriter myWriter = new FileWriter("Flash Loader.html");
        myWriter.write(starthtml+sc+endhtml);
        myWriter.close();
        System.out.println("Successfully wrote to the file");
      } catch (IOException e) {
        System.out.println("An error occurred");
        e.printStackTrace();
      }
  }
}

Error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

at CreateFile.main(Flash_Loader_Creator.java:10)

Solution

  • Renaming my .java file to CreateFile.java fixed the issue thank you https://stackoverflow.com/users/1081110/dawood-says-reinstate-monica https://stackoverflow.com/users/1902512/haibrayn-gonz%c3%a1lez