List of usage examples for java.io File File
public File(URI uri)
From source file:Main.java
public static void main(String[] args) throws Exception { ZipFile zipFile = new ZipFile(new File("testfile.zip"), ZipFile.OPEN_DELETE); Enumeration zipEntries = zipFile.entries(); while (zipEntries.hasMoreElements()) { System.out.println(((ZipEntry) zipEntries.nextElement()).getName()); }/*from ww w . j a v a 2 s . c o m*/ }
From source file:Main.java
public static void main(String args[]) throws IOException { File file = new File("your_file.jpg"); BufferedImage image = ImageIO.read(file); int x = 10;//ww w .jav a2 s . co m int y = 10; int clr = image.getRGB(x, y); int red = (clr & 0x00ff0000) >> 16; int green = (clr & 0x0000ff00) >> 8; int blue = clr & 0x000000ff; System.out.println("Red Color value = " + red); System.out.println("Green Color value = " + green); System.out.println("Blue Color value = " + blue); }
From source file:Main.java
public static void main(String[] argv) throws Exception { File file = new File("filename"); FileChannel channel = new RandomAccessFile(file, "rw").getChannel(); FileLock lock = channel.lock(); lock = channel.tryLock();/* w ww .j av a 2 s.com*/ lock.release(); channel.close(); }
From source file:MainClass.java
public static void main(String[] args) { File originFile = new File("c:\\file1.txt"); File destinationFile = new File("c:\\file1.txt"); if (!originFile.exists() || destinationFile.exists()) { return;//from w w w. ja v a 2 s . c om } try { byte[] readData = new byte[1024]; FileInputStream fis = new FileInputStream(originFile); FileOutputStream fos = new FileOutputStream(destinationFile); int i = fis.read(readData); while (i != -1) { fos.write(readData, 0, i); i = fis.read(readData); } fis.close(); fos.close(); } catch (IOException e) { System.out.println(e); } }
From source file:Main.java
public static void main(String[] args) throws Exception { File aFile = new File("C:/test.bin"); FileInputStream inFile = new FileInputStream(aFile); FileChannel inChannel = inFile.getChannel(); final int PRIMECOUNT = 6; ByteBuffer buf = ByteBuffer.allocate(8 * PRIMECOUNT); long[] primes = new long[PRIMECOUNT]; while (inChannel.read(buf) != -1) { ((ByteBuffer) (buf.flip())).asLongBuffer().get(primes); for (long prime : primes) { System.out.printf("%10d", prime); }// w w w. j av a 2s .c o m buf.clear(); } inFile.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFileChooser chooser = new JFileChooser(); File f = new File(new File(".").getCanonicalPath()); chooser.setCurrentDirectory(f);//from www .ja va 2 s. co m chooser.setCurrentDirectory(null); chooser.showOpenDialog(null); JComponent obj = chooser.getAccessory(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { File file = new File("filename"); FileChannel channel = new RandomAccessFile(file, "rw").getChannel(); MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_WRITE, 0, (int) channel.size()); buf.put(0, (byte) 0xFF); System.out.println(buf.isLoaded()); buf.force();//from w w w . j a v a 2s . c o m channel.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { File file = new File("c:\\"); URL url = file.toURI().toURL(); URL[] urls = new URL[] { url }; ClassLoader cl = new URLClassLoader(urls); Class cls = cl.loadClass("com.mycompany.MyClass"); }
From source file:CopyBytes.java
public static void main(String[] args) throws IOException { File inputFile = new File("input.txt"); File outputFile = new File("output.txt"); FileInputStream in = new FileInputStream(inputFile); FileOutputStream out = new FileOutputStream(outputFile); int c;/*from ww w .j ava 2s .c o m*/ while ((c = in.read()) != -1) out.write(c); in.close(); out.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { File file = new File("filename"); FileChannel channel = new RandomAccessFile(file, "rw").getChannel(); FileLock lock = channel.lock(0, Long.MAX_VALUE, true); lock = channel.tryLock(0, Long.MAX_VALUE, true); boolean isShared = lock.isShared(); lock.release();//from ww w .j a v a 2 s .c om channel.close(); }