Files not generating on dedicated servers

Discussion in 'Spigot Plugin Development' started by craterhater, May 30, 2017.

  1. Hey there,

    I am using this code:
    Code (Text):
        public void addData(String file, String set, String data, String folder) throws IOException{
            File f = new File(main.getDataFolder() + "\\"+folder, file+".yml");
            f.createNewFile();
            List<String> lines = new ArrayList<String>();

            String line;
            try (
                InputStream fis = new FileInputStream(f);
                InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8"));
                BufferedReader br = new BufferedReader(isr);
            ) {
                while ((line = br.readLine()) != null) {
                    lines.add(line);
                }
                fis.close();
                isr.close();
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            String c = null;
            for(String s : lines){
                if(s.contains(set)){
                    c = s;
                }
            }
            if(c != null){
                removeLineFromFile(main.getDataFolder()+"\\data\\"+file+".yml",c);
            }
           
                FileWriter fw = new FileWriter(f,true);
                BufferedWriter bw = new BufferedWriter(fw);
                bw.append(set+ ": " + data);
                bw.newLine();
                bw.close();
                fw.close();
        }
    to add data to a file. However, on dedicated servers the files cannot be created. Anyone got any idea why?
     
  2. #setWritable()?

    Never had this problem. Did you make sure to give the spigot file permissions?
     
  3. If you don't have windows on your server you should use normal slashes instead of backslashes
     
  4. How do I make it compatible for both?
     
  5. Use
    Code (Java):
    File.separator