Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void rm(String sourcePath) {
- File f= new File (sourcePath);
- File f1= new File (Dd+sourcePath);
- if (f1.exists()) {
- if(f.delete())
- System.out.println("deleted");
- else
- System.out.println("Not deleted");
- }
- else if (f.exists()) {
- if(f.delete())
- System.out.println("deleted");
- else
- System.out.println("Not deleted");
- }
- }
- public Boolean cp(String sourcePath, String destinationPath ) {
- String a="";
- File f =new File(sourcePath);
- File f1= new File (Dd+sourcePath);
- if (f1.exists()) {
- a=Dd+sourcePath;
- }
- else if (f.exists()) {
- a=sourcePath;
- }
- else {
- System.out.println("can't find source to copy");
- return false;
- }
- try {
- FileReader myReader= new FileReader(a);
- File file1= new File(destinationPath);
- File file2= new File(Dd+destinationPath);
- String b;
- if (file2.createNewFile()||file2.exists()) {
- b=Dd+destinationPath;
- }
- else if (file1.createNewFile()||file1.exists()) {
- b=destinationPath;
- }
- else {
- System.out.println("wrong destination path");
- return false;
- }
- FileWriter myWriter= new FileWriter(b);
- Scanner read= new Scanner(myReader);
- String s;
- while (read.hasNextLine()) {
- s = read.nextLine();
- myWriter.write(s+"\n");
- }
- myReader.close();
- myWriter.close();
- read.close();
- return true;
- }
- catch(IOException e) {
- System.out.println("wrong input");
- return false;}
- }
- public void mv(String sourcePath, String destinationPath )throws IOException{
- if(cp( sourcePath, destinationPath ))
- rm(sourcePath);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement