I just want to create an txt file and add text to it with a command. SO i need at least 2 classes and i dont care if yml or not but it should not be the config.yml cuz i need it as an "log" for something. I dont know how and i googled but i didnt find something so i ask u guys. thanks ~ malte
@Nayetlam http://stackoverflow.com/questions/2885173/how-to-create-a-file-and-write-to-a-file-in-java http://www.mkyong.com/java/how-to-write-to-file-in-java-bufferedwriter-example/ https://docs.oracle.com/javase/tutorial/essential/io/file.html http://www.codejava.net/java-se/file-io/how-to-read-and-write-text-file-in-java https://bukkit.org/threads/tut-custom-yaml-configurations-with-comments.142592/
@Nayetlam as with all files when reading or writing to you'll need a File instance. to get this file you make do (new file(pluginfolder, filename).. then check if it exists if not you create it. if you are writing with a .yml file make sure to have in the filename .yml instead of .txt and parse it to the YamlConfiguration. with writing there is a simple FileOutPutStream and FileInPutStream that writes to or reads from the file. for the .yml file you use it as a regular config file. please note for when working with a .yml file always save after you did you writing since it won't save automaticly
ok thanks dude i try my best even if i m not good with config haha Code: // I did this in main class. public static File pluginfile = new File("plugins/ETLAM/log.yml"); public static void PaylogFile() { if (!pluginfile.exists()){ try { pluginfile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } } //BUt i dont have a clue how to write to it from another class or how to add text cuz im not intelligent. <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
im sitting here for three hours but im too dumb cant u just tell me?. Look i have an extra class where it creates the file but i dont have a fckn clue how to make that it creates that file plus i am too dumb to get the strings from my command class into that class where i want to write something. please PLEASE i m sitting here for so long and i read so many articles in the internet but i cant find it. I dont want to write some letters i want a log.txt where some arguments (strings in that case) from my command executor save, can't u just tell me HOW to connect them and i dont mean the pure code and stuff
yes but look i create the file, than how the daymn my plugin should open the file instantly`? Doin it in main class? Okay. But is there also infomation how i can operate with the file in OTHER classes? Cuz i cant just create private and public static stuff and just do it and stuff. IS the info there too? I am too dumb to find it maybe. EDIT: I dont want to write some letters i want a log.txt where some arguments (strings in that case) from my command executor save, can't u just tell me HOW to connect them and i dont mean the pure code and stuff
@Nayetlam Jeez.. here's how you can write to a file: Code: public static void writeToLog(File file, String s) throws IOException { YamlConfiguration c = new YamlConfiguration(); FileUtils.writeStringToFile(new File("plugins/" + File.separator + "myPlugin", "logs"+ ".yml"), s); c.save(new File("plugins/" + File.separator + "myPlugin", "logs"+ ".yml")); } You can figure out how to read it yourself