Solved Creating new file

Discussion in 'Plugin Development' started by HeyAwesomePeople, Jun 15, 2014.

Thread Status:
Not open for further replies.
  1. I have no idea whats going on here. Something is wrong but I cannot figure it out. I am trying to create a logs file, under /plugins/KitPVP/Logs/minilog-date.txt.
    Here is my code:
    PHP:
        private File logsDir = new File(plugin.getDataFolder(), "Logs");
     
        public 
    void makeDirs() {
            if (!
    logsDir.exists()) {
                
    logsDir.mkdir();
            }
        }
     
        public 
    void makeMiniLog() {
            if (!new 
    File(logsDir File.separator "minilog-" getDateAsString()
                    + 
    ".txt").exists()) {
                
    File todayFile = new File(logsDir File.separator "minilog-"
                        
    getDateAsString() + ".txt");
                try {
                    
    todayFile.createNewFile(); // Error
                
    } catch (IOException e) {
                    
    e.printStackTrace();
                }
            }
        }
    I get an error on todayFile.createNewFile() when trying to start up the server. This is the error:

    Code:
    [16:19:57] [Server thread/WARN]: java.io.IOException: The system cannot find the path specified
    [16:19:57] [Server thread/WARN]:at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    [16:19:57] [Server thread/WARN]:at java.io.File.createNewFile(Unknown Source)
    [16:19:57] [Server thread/WARN]:at me.HeyAwesomePeople.kitpvp.Logging.Logs.makeMiniLog(Logs.java:31)
    [16:19:57] [Server thread/WARN]:at me.HeyAwesomePeople.kitpvp.KitPVP.onEnable(KitPVP.java:172)
    [16:19:57] [Server thread/WARN]:at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:250)
    [16:19:57] [Server thread/WARN]:at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324)
    [16:19:57] [Server thread/WARN]:at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404)
    [16:19:57] [Server thread/WARN]:at org.bukkit.craftbukkit.v1_7_R3.CraftServer.loadPlugin(CraftServer.java:441)
    [16:19:57] [Server thread/WARN]:at org.bukkit.craftbukkit.v1_7_R3.CraftServer.enablePlugins(CraftServer.java:375)
    [16:19:57] [Server thread/WARN]:at net.minecraft.server.v1_7_R3.MinecraftServer.n(MinecraftServer.java:352)
    [16:19:57] [Server thread/WARN]:at net.minecraft.server.v1_7_R3.MinecraftServer.g(MinecraftServer.java:326)
    [16:19:57] [Server thread/WARN]:at net.minecraft.server.v1_7_R3.MinecraftServer.a(MinecraftServer.java:282)
    [16:19:57] [Server thread/WARN]:at net.minecraft.server.v1_7_R3.DedicatedServer.init(DedicatedServer.java:182)
    [16:19:57] [Server thread/WARN]:at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:436)
    [16:19:57] [Server thread/WARN]:at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628)
    What's going on?
     
  2. Offline

    HeadGam3z

    Just to point this out:
    Code:java
    1. [16:19:57] [Server thread/WARN]: java.io.IOException: The system cannot find the path specified



    Looks like the path you gave it cannot be found.
     
  3. Offline

    krazytraynz

    Do you ever call makeDirs() before you try to create the file?
     
  4. Offline

    RawCode

    try adding debug output to your code.

    in this case show name of file to be opened\created
     
    xTigerRebornx likes this.
  5. krazytraynz Yes
    HeadGam3z I make the dirs, and the dir IS there in the folder, when I call the method to make the actual file.
     
  6. Offline

    amhokies

    File todayFile = new File(logsDir + File.separator + "minilog-"+ getDateAsString() + ".txt");

    logsDir is not a String object, yet you are trying to treat it as such. Use the two arg File constructor that you used before with the parent directory as the first argument, then the String relative path as the second. HeyAwesomePeople
     
  7. I just realized that the date format contains "/", which would make it look for a random directory...
    Thanks guys
     
Thread Status:
Not open for further replies.

Share This Page