Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (message.toLowerCase().startsWith("!whitelist @")) {
- String msg = message.substring(message.lastIndexOf("@", message.length())) + "\r\n";
- try{
- BufferedWriter bw = new BufferedWriter(new FileWriter(new File(Paths.get("./whitelist.txt").toUri())));
- try {
- System.out.println("Writing to file:");
- bw.write(msg);
- bw.write(msg + "this is a test bla bla bla \n test test test");
- // group.sendMessage(message.substring(message.lastIndexOf("@"), message.length()) + " has been added to the whitelist"); //should only show message if they are actually added to the whitelist
- } catch (IOException e) { // This means that for some reason it failed to write the message
- //let it crash, or handle the exception
- } finally { //always runs, whether or not an exception is thrown
- bw.flush(); //MUST FLUSH AND CLOSE THE STREAM EVEN IF IT FAILS TO WRITE TO THE FILE TO PREVENT MEMORY LEAKS
- bw.close();
- }
- }
- catch (IOException e){
- System.out.println("Unable to access file");
- //let it crash, or handle the exception
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement