Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners how to backup files and folder with Java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Sean
how to backup files and folder with Java
2 Answer(s)      a year and 6 months ago
Posted in : Java Beginners


Does anyone know to create a backup with java?. backup files and folders from my computer to an external drive.


Advertisement
View Answers

May 30, 2013 at 1:27 PM


hi friend,

Try the following code may, this will be helpful for you

package net.roseindia;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

public class CreateBackupFile{
    public void createBackup(String filename, String... content)
                        throws IOException{
        File originalFile = new File(filename);     
        File backupFile = new File(originalFile.getCanonicalPath() + ".backup");

        originalFile.renameTo(backupFile);
        PrintWriter output = new PrintWriter(originalFile);
        for(String fileData : content){
            output.println(fileData);
        }
        output.close();
    }

    public static void main(String args[])
    {
        CreateBackupFile create = new CreateBackupFile();
        String fileName = "C:\\Documents and Settings\\bharat\\Desktop\\bipul\\New Folder\\TableExample.java";
        File file = new File(fileName);
        BufferedReader br = null;
        String str ="";     

        try {
            br = new BufferedReader(new FileReader(file));
            StringBuilder sb = new StringBuilder();
            while ((str = br.readLine()) != null) {
                sb.append(str);
            }
            br.close();
            String str1 = sb.toString();            
            create.createBackup(fileName, str1);
            System.out.println(str1);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Thanks.



May 31, 2013 at 6:24 AM


thanks, very nice code.



Related Tutorials/Questions & Answers:
how to backup files and folder with Java
how to backup files and folder with Java  Does anyone know to create a backup with java?. backup files and folders from my computer to an external...(originalFile.getCanonicalPath() + ".backup"); originalFile.renameTo
how to download the uploaded folder files using jsp
how to download the uploaded folder files using jsp  how to download the uploaded folder files using jsp
Advertisements
How to copy files from one folder to another based on lastmodified date - Java Beginners
Copy files from one folder to another  How to copy files from one folder to another based on lastmodified date
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?  i have multiple(app..100) text files which has data in the form of intgers consisting of 3 columns and app..3000
java program to take the backup of folders and copy the folder in different location without deleting the existing one
java program to take the backup of folders and copy the folder in different... the backup of folders and copy the folder in different location without deleting the existing one   Have a look at the following link: Java Copy one folder
How to copy files from one folder to another based on lastmodified date - Java Beginners
How to copy files from one folder to another based on lastmodified date  I have to make a simple utility to copy files from a folder to another folder in the same hierarchy, without overwriting the existing.  hiimport
files that are present in any folder , how to make it clickable downloadble file in php
files that are present in any folder , how to make it clickable downloadble file in php   files that are present in any folder , how to make it clickable downloadble file in php
how to upload multiple files in jsp and saving the path in database and the file in folder
how to upload multiple files in jsp and saving the path in database and the file in folder  how to upload multiple files in jsp and saving the path in database and the file in folder I have created a form for the upload of files
Java backup pst file
Java backup pst file  Hello!! i need some help please. Im new in Java. How can i create a java program to backup any files and folders (like PST files)in my computer at a specific time
how to backup and restore database using java - Swing AWT
how to backup and restore database using java  sir my project is to backup and restore my datas using java so i want to know how to backup and restore databases using java give ur ideas and suggestions to me immediately  
how to take backup of phone to pc using java code
how to take backup of phone to pc using java code  i want to take the backup of phone data in my pc and also provide the restore functionality,and i want to do it using java program,so can anyone help me
Java Util Zip. Zip files/folders inside a folder, without zipping the original source folder.
Java Util Zip. Zip files/folders inside a folder, without zipping the original source folder.   import java.io.File; import... the method a very static scenario. I want to take the files inside the folder
PHP listing files in folder
All files, folder   of the given folder can be listed. Function readdir() takes input as the folder handle. Then readdir() returns the name of all the files and folders. Example of PHP Listing Files in Folder
How I Choose a folder - Java Interview Questions
do not explain clearly my question. I know how I get files from a folder. My question How I select a folder. From this selected folder i get the files. I know how I get files but the problem How I choose a folder. Thanks
java program to take backup for the folders
java program to take backup for the folders  java program to take backup for the folders   Have a look at the following link: Java Copy one folder to another
Folder in Java.
Folder in Java.  I have any problem how to make Folder in java program? Can Anybody help me in this part
how to take a backup of a table in sql
how to take a backup of a table in sql  how to take a backup of a table in sql?   SQL BackUp Table example
How to upload and save a file in a folder - Java Beginners
How to upload and save a file in a folder  Hi How to upload and save a file in a folder? for example Agreement.jsp File: So when..., Thanks for your code.... Do i need any jarfiles to be placed in lib? Java
Zip Folder Using Java
; In this example we are going to create a zip folder and all files contained in this folder are zipped by using java. Here we will learn how to compress files... of folders. The list() method is used to find list of files in a folder. By using
Monitor the Folder for the new incoming files - Development process
Monitor the Folder for the new incoming files  to monitor the whole folder for new incoming files ,which the client will place...Monitor the Folder for the new incoming files   Hi,The simplest way to achieve
How to avoid Java Code in JSP-Files?
How to avoid Java Code in JSP-Files?  How to avoid Java Code in JSP-Files
How do I decompile Java class files?
How do I decompile Java class files?  How do I decompile Java class files
Zipping folder - Java Beginners
to zip a user selected folder . this folder may contain any number of folder and sub folders. i saw an example in this site showing , how to zip a folder, i executed... solve this.. zipping folder and all of its files and sub folders. thanking
how to download a file from a folder??
how to download a file from a folder??  i can upload any kind of files to a folder, and only the path of the file is saved into the database, now how a client can download the file from my folder. pls provide me the jsp code
How to delete files in Java?
Delete a File using File Class Object       Delete a File using File Class Object In this section, you will learn how to delete a file. 
Zipping folder - Java Beginners
to zip a user selected folder . this folder may contain any number of folder and sub folders. i saw an example in this site showing , how to zip a folder, i executed... solve this.. zipping folder and all of its files and sub folders. thanking
How to convert multiple files in java to .zip format
How to convert multiple files in java to .zip format  i receive multiple files from a remote URL as for (String reportid : reportList...[]args){ CreateJar jar=new CreateJar(); File folder = new File("C
copy file from folder to folder - Java Beginners
copy file from folder to folder   my requirement is I need to copy xml files from one folder to another my source file contains the field filename.... Suppose in the source file, file name is goodfile1.xml source folder
Java lock file or folder.
Java lock file or folder.  Is it possible to create a desktop application to lock or encrypt file or folder in windows by using java code?? if possible can provide some reference?? because i can't find it... thanks
how to set folder size in php
how to set folder size in php  hi , i know how to create folder but i dont know how to set size for folder did u know means tell me. thankyour
how to take iphone backup using itunes
how to take iphone backup using itunes  Hi, Can anyone please tell me how to take iphone backup using itunes..?   You can find the details on apple website as well... anyhow i am giving you some tips as follow... How
Advertisements
 

 

 

DMCA.com