Advertisement
droidus

taskBckg

Jan 28th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileReader;
  6. import java.io.FileWriter;
  7. import java.io.IOException;
  8. import java.io.InputStreamReader;
  9. import java.io.PrintWriter;
  10. import java.util.Scanner;
  11. import java.util.regex.Matcher;
  12. import java.util.regex.Pattern;
  13.  
  14. public class taskBckg {
  15.    
  16.    
  17.    
  18.     // Returns true if file exists
  19.         public static boolean checkForFile() throws IOException {
  20.             File f = new File("tasks.txt");
  21.             if (!f.exists()) {
  22.                 // Create the file
  23.                 createTasksFile();
  24.             } else {
  25.                 return true;
  26.             }
  27.             return false;
  28.         }
  29.        
  30.         public void openWebpage(String address) {
  31.             try
  32.             {
  33.             Process p=Runtime.getRuntime().exec("cmd /c start "+ address);
  34.             }
  35.             catch(IOException e1) {
  36.                 System.out.println(e1);
  37.                 }
  38.         }
  39.        
  40.        
  41.        
  42.        
  43.        
  44.        
  45.        
  46.        
  47.        
  48.        
  49.         // Returns true if errors still exist
  50.         @SuppressWarnings("null")
  51.         public static String[] runDiagnostics() throws IOException {
  52.            
  53.             gui gui1 = new gui();
  54.             gui1.setCurStatus("Now running diagnostics... Please wait!");
  55.            
  56.             int i = 0;
  57.             int errorsI = 0;
  58.             File f = new File("tasks.txt");
  59.             String[] errors = { "", "", "", "", "" };
  60.  
  61.             // try to create the file three times
  62.             do {
  63.                 f.createNewFile();
  64.                 i++;
  65.             } while (!f.exists() && i < 3);
  66.  
  67.             // if the file creating was still unsuccessful, give out an error
  68.             if (!f.exists()) {
  69.                 errors[errorsI] = "Error creating the file!";
  70.                 errorsI++;
  71.             }
  72.             if (!f.canRead()) {
  73.                 errors[errorsI] = "Error reading the file!";
  74.                 errorsI++;
  75.             }
  76.             if (!f.canWrite()) {
  77.                 errors[errorsI] = "Error writing to the file!";
  78.                 errorsI++;
  79.             }
  80.             return errors;
  81.         }
  82.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement