HaniiPuppy

Weirdness.

Feb 18th, 2016
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1.     public void localiseFile(File m3uFile, boolean replaceInsteadOfCopy) throws FileNotFoundException
  2.     {
  3.         try
  4.         {
  5.             if(!m3uFile.exists())
  6.                 throw new FileNotFoundException("M3U file at path doesn't exist: " + m3uFile.toString());
  7.            
  8.             File saveFile = new File(getSaveFilePathFromLoadFilePath(m3uFile.getCanonicalPath()));
  9.             saveFile.mkdirs();
  10.            
  11.             if(saveFile.exists())
  12.                 saveFile.delete();
  13.            
  14.             saveFile.createNewFile();
  15.            
  16.             DataInputStream input = new DataInputStream(new FileInputStream(m3uFile));
  17.             BufferedReader reader = new BufferedReader(new InputStreamReader(input));
  18.            
  19.             FileWriter output = new FileWriter(saveFile, true);
  20.             PrintWriter writer = new PrintWriter(output);
  21.  
  22.             boolean firstLine = true;
  23.            
  24.             try
  25.             {
  26.                 for(String line = ""; line != null; line = reader.readLine())
  27.                     if(firstLine)
  28.                     {
  29.                         writer.print(localiseFileLine(m3uFile.getParentFile(), line));
  30.                         firstLine = false;
  31.                     }
  32.                     else
  33.                         writer.println(localiseFileLine(m3uFile.getParentFile(), line));
  34.             }
  35.             finally
  36.             {
  37.                 input.close();
  38.                 reader.close();
  39.                 writer.flush();
  40.                 writer.close();
  41.                 output.close();
  42.             }
  43.            
  44.             if(replaceInsteadOfCopy)
  45.             {
  46.                 m3uFile.delete();
  47.                 saveFile.renameTo(m3uFile);
  48.             }
  49.         }
  50.         catch(IOException exception)
  51.         {
  52.             if(exception instanceof FileNotFoundException)
  53.                 throw (FileNotFoundException)exception;
  54.                
  55.             throw new RuntimeException("Unexpected IO exception", exception);
  56.         }
  57.        
  58.         jLabel1.setText("Localised!");
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment