JavaScript - JavaScript Bible (Gold Edition)
JavaScript - JavaScript Bible (Gold Edition)
package epn.javaadv.stream;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
Class to manage the general operations of files using JAVA,
in which the use of the fundamental objects FileReader, FileWriter will be demonstrated
* @author martosfre
See www.matoosfe.com
Sep 23, 2010
*/
public class AdminArchivo {
/**
Method to create a directory, it is not necessary to calculate the IOException exception
* @param directoryName
* @param path
* @return
*/
public boolean createDirectory(String directoryName, String path){
File directory = new File(path + File.separatorChar + directoryName);
return directory.mkdir();
}
/**
Method to copy the content of one file to another
* @param sourceFile
* @param destinationFile
* @return
* @throws IOException
* @throws ClassNotFoundException
*/
public boolean copyFileContent(File sourceFile, File destinationFile) throws IOException,
ClassNotFoundException{
/**
Method to recover the files given a directory
* @param directory
* @return
*/
public File[] recoverFilesFromDirectory(File directory) throws IOException{
/**
Method for writing data to a file
* @return
*/
public File writeFile() {
return null;
/**
Method to move a file from one location to another
* @return
*/
public boolean moveFile() {
return false;
}
/**
Method to modify a file following what is already there
* @return
*/
public boolean modifyFile() {
return false;
}
try {
The sourceFile.txt must be created beforehand before proceeding as it is the data source.
File sourceFile = new File(fileLocation + File.separatorChar + "sourceFile.txt");
File destinationFile = new File(fileLocation + File.separatorChar + "destinationFile.txt");
We verify that the directory exists
if(new File(locationFile + File.separatorChar + "cec_epn").exists()){
:
if(successfulCopy){
adminArc.retrieveDirectoryFiles(new File(fileLocation));
}
translatedText
if(adminArc.createDirectory("cec_epn", fileLocation)){
boolean successfulCopy = adminArc.copyFileContent(sourceFile, destinationFile
if(successfulCopy){
adminArc.recoverFilesDirectory(new File(fileLocation));
}
else {
Problems creating directory, possible permission error
}
}
} catch (IOException e) {
System.out.println("Error IO:" + e.getMessage());
e.printStackTrace();
catch (ClassNotFoundException e) {
System.out.println("Error CNF:" + e.getMessage());
e.printStackTrace();
}catch(Exception e){
System.out.println("General Error:" + e.getMessage());
}
}
}
2 of 2 09/18/2012 16:08