Files

Discussion in 'Plugin Development' started by WarmakerT, Oct 6, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    WarmakerT

    File file = new File("plugins/ThisIsThePluginsDirectory/Log.txt");

    It throws a java.io.IOException. "java.io.IOException The system was not able to find the specified path"

    Could you help? Thanks in advance :)
     
  2. Offline

    willeb96

    Try this instead

    PHP:
    File file = new File("../ThisIsThePluginsDirectory/Log.txt");
    I don't know if it will work, it's just what I would have tried :)
     
  3. Offline

    WarmakerT

    I get the same error =\ .

    If this helps at all:
    Code:java
    1.  
    2. public void writeToFile(String str){
    3. try {
    4. File file = new File("../ThisIsAPlugin/Log.txt");
    5.  
    6. if(file.exists() == false){
    7. file.createNewFile();
    8. }
    9.  
    10. BufferedWriter output = new BufferedWriter(new FileWriter(file, true));
    11. output.write(str);
    12. output.newLine();
    13. output.close();
    14. this.getLogger().log(Level.INFO, str);
    15. } catch (IOException ex) {
    16. Logger.getLogger(ThisIsAPlugin.class.getName()).log(Level.SEVERE, null, ex);
    17. }
    18. }
    19.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  4. Offline

    Cirno

    Ahhh, I remember working with files...
    It was a pain. But it pays.
    Just pulled this out of ImgMap:
    Code:JAVA
    1. File f = new File(cirno.getDataFolder().getAbsoluteFile(), "\\MapData.list");


    cirno is the JavaPlugin class.
     
    WarmakerT likes this.
  5. Offline

    WarmakerT

    Thanks Cirno :)
     
  6. Offline

    Cirno

    Could be possibly that the folder doesn't exist.
    Got lazy, just copypasta'd my own source.
    Code:JAVA
    1. public void initializeFile() throws IOException{
    2. File f = new File(cirno.getDataFolder().getAbsoluteFile(), "\\MapData.list");
    3. File folder = new File(cirno.getDataFolder().getAbsoluteFile().getAbsolutePath());
    4. if(!folder.exists()){
    5. folder.mkdir();
    6. }
    7. if(!f.exists()){
    8. f.createNewFile();
    9. }
    10. FileSafeForUse = true;
    11. }
     
  7. Offline

    WarmakerT

    Yeah, I figured that out :) Thanks!
     
  8. notice this dont works on linux, and most server use linux these days, use an "/" for linux (also works on windows)
     
Thread Status:
Not open for further replies.

Share This Page