Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void localiseFile(File m3uFile, boolean replaceInsteadOfCopy) throws FileNotFoundException
- {
- try
- {
- if(!m3uFile.exists())
- throw new FileNotFoundException("M3U file at path doesn't exist: " + m3uFile.toString());
- File saveFile = new File(getSaveFilePathFromLoadFilePath(m3uFile.getCanonicalPath()));
- saveFile.mkdirs();
- if(saveFile.exists())
- saveFile.delete();
- saveFile.createNewFile();
- DataInputStream input = new DataInputStream(new FileInputStream(m3uFile));
- BufferedReader reader = new BufferedReader(new InputStreamReader(input));
- FileWriter output = new FileWriter(saveFile, true);
- PrintWriter writer = new PrintWriter(output);
- boolean firstLine = true;
- try
- {
- for(String line = ""; line != null; line = reader.readLine())
- if(firstLine)
- {
- writer.print(localiseFileLine(m3uFile.getParentFile(), line));
- firstLine = false;
- }
- else
- writer.println(localiseFileLine(m3uFile.getParentFile(), line));
- }
- finally
- {
- input.close();
- reader.close();
- writer.flush();
- writer.close();
- output.close();
- }
- if(replaceInsteadOfCopy)
- {
- m3uFile.delete();
- saveFile.renameTo(m3uFile);
- }
- }
- catch(IOException exception)
- {
- if(exception instanceof FileNotFoundException)
- throw (FileNotFoundException)exception;
- throw new RuntimeException("Unexpected IO exception", exception);
- }
- jLabel1.setText("Localised!");
- }
Advertisement
Add Comment
Please, Sign In to add comment