Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package JavaIO;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.RandomAccessFile;
- public class Juni2014 {
- public static void manage (String in,String out) throws IOException {
- File sourceFolder = new File(in);
- File destinationFolder = new File(out);
- if (!sourceFolder.exists()) {
- System.out.println("Ne postoi" + in);
- }
- else {
- if(!sourceFolder.isDirectory()) {
- System.out.println(in + "Ne e direktorium");
- } else {
- if(destinationFolder.exists())
- {
- if(destinationFolder.isDirectory()) {
- File[] lista = destinationFolder.listFiles();
- for (File fajl : lista)
- fajl.delete();
- } else {
- System.out.println(out + "Ne e direktorium");
- return;
- }
- }
- else
- destinationFolder.mkdirs();
- File[] lista = sourceFolder.listFiles();
- for (File f : lista) {
- if(f.getName().endsWith(".dat")) {
- if(f.isHidden()) {
- f.delete();
- System.out.println("Zbunet sum " + f.getAbsolutePath());
- } else {
- if(f.canWrite()) {
- System.out.println("Pomestuvam " + f.getAbsolutePath());
- f.renameTo(new File(destinationFolder,f.getName()));
- }
- else {
- File zaPisuvanje = new File("resources/writible-content.txt");
- readFromSourceAppendToDestination(f,zaPisuvanje);
- System.out.println("Dopisuvam " + f.getAbsolutePath());
- }
- }
- }
- }
- }
- }
- }
- private static void readFromSourceAppendToDestination(File source,File destination) throws IOException {
- // TODO Auto-generated method stub
- RandomAccessFile vlez = null;
- RandomAccessFile izlez = null;
- try {
- vlez = new RandomAccessFile(source,"r");
- izlez = new RandomAccessFile(destination, "rw");
- izlez.seek(izlez.length());
- int b;
- while ((b = vlez.read()) != -1)
- izlez.write(b);
- }
- finally {
- if(izlez != null){
- izlez.close();
- }
- if(vlez != null) {
- vlez.close();
- }
- }
- }
- public static void main(String[] args) throws IOException {
- // TODO Auto-generated method stub
- manage("in","out");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement