1 19 20 24 25 package org.netbeans.modules.css; 26 27 import java.io.File ; 28 import java.io.FileInputStream ; 29 import java.io.FileOutputStream ; 30 import java.io.IOException ; 31 import java.nio.channels.FileChannel ; 32 import java.security.AccessController ; 33 import java.security.PrivilegedAction ; 34 import javax.swing.JFileChooser ; 35 36 41 public class Utilities { 42 43 48 public static JFileChooser getJFileChooser() { 49 return (JFileChooser )AccessController.doPrivileged(new PrivilegedAction <Object >() { 50 public Object run() { 51 return new JFileChooser () ; 52 } 53 }); 54 } 55 56 public static JFileChooser getJFileChooser(final String currentDirectoryPath) { 57 return (JFileChooser )AccessController.doPrivileged(new PrivilegedAction <Object >() { 58 public Object run() { 59 return new JFileChooser (currentDirectoryPath); 60 } 61 }); 62 } 63 64 public static JFileChooser getJFileChooser(final java.io.File currentDirectory) { 65 return (JFileChooser )AccessController.doPrivileged(new PrivilegedAction <Object >() { 66 public Object run() { 67 return new JFileChooser (currentDirectory) ; 68 } 69 }); 70 } 71 72 public static void copyFile(File sourceFile, File destFile) throws IOException { 73 if(!destFile.exists()) { 74 destFile.createNewFile(); 75 } 76 77 FileChannel source = null; 78 FileChannel destination = null; 79 try { 80 source = new FileInputStream (sourceFile).getChannel(); 81 destination = new FileOutputStream (destFile).getChannel(); 82 destination.transferFrom(source, 0, source.size()); 83 } finally { 84 if(source != null) { 85 source.close(); 86 } 87 if(destination != null) { 88 destination.close(); 89 } 90 } 91 } 92 } 93 | Popular Tags |