- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStream;
-
-
- /**
- * @author Macrosjiu
- *
- */
- public class FileLayerUtilities {
-
- public static void saveInFile(String completePathFile, InputStream in) throws IOException{
- BufferedInputStream bis = new BufferedInputStream(in);
- File file = new File(completePathFile);
- if(!file.exists())
- file.createNewFile();
-
- FileOutputStream stream = new FileOutputStream(completePathFile);
- BufferedOutputStream bos = null;
- try {
- int read_bytes = 0;
- byte[] buffer = new byte[4096];
- bos = new BufferedOutputStream(stream, buffer.length);
- while ( (read_bytes = bis.read(buffer, 0, buffer.length)) != -1) {
- bos.write(buffer,0, read_bytes);
- }
- }catch(IOException ex){
- throw new IOException("ERROR IN SAVING FILE !! pathFile : "+file.getAbsolutePath());
- } finally {
- bos.flush();
- bos.close();
- stream.close();
- }
-
- }
-
- public static void deleteFile(String completePathFile) throws IOException{
- try{
- File filetoDelete = new File (completePathFile);
- if(filetoDelete.exists()){
- if( ! filetoDelete.delete())
- throw new IOException("ERROR FILE NOT DELETED !! pathFile : "+filetoDelete.getAbsolutePath());
- }
- }catch(IOException ex){
- throw new IOException("Error in deleting file");
- }
- }
-
- public static InputStream readFile(String completePathFile) throws IOException{
- try{
- File file = new File(completePathFile);
- if(file.exists()){
- InputStream in = new FileInputStream(file);
- //byte myBytes[] = new byte[in.available()];
- //in.read(myBytes);
- //return new String(myBytes);
- return in;
- }else{
- throw new IOException("FILE TO READ NOT FOUND !! pathFile : "+file.getAbsolutePath());
- }
- }catch(IOException ex){
- throw new IOException("Error in reading file");
- }
- }
-
- }
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
/**
* @author Macrosjiu
*
*/
public class FileLayerUtilities {
public static void saveInFile(String completePathFile, InputStream in) throws IOException{
BufferedInputStream bis = new BufferedInputStream(in);
File file = new File(completePathFile);
if(!file.exists())
file.createNewFile();
FileOutputStream stream = new FileOutputStream(completePathFile);
BufferedOutputStream bos = null;
try {
int read_bytes = 0;
byte[] buffer = new byte[4096];
bos = new BufferedOutputStream(stream, buffer.length);
while ( (read_bytes = bis.read(buffer, 0, buffer.length)) != -1) {
bos.write(buffer,0, read_bytes);
}
}catch(IOException ex){
throw new IOException("ERROR IN SAVING FILE !! pathFile : "+file.getAbsolutePath());
} finally {
bos.flush();
bos.close();
stream.close();
}
}
public static void deleteFile(String completePathFile) throws IOException{
try{
File filetoDelete = new File (completePathFile);
if(filetoDelete.exists()){
if( ! filetoDelete.delete())
throw new IOException("ERROR FILE NOT DELETED !! pathFile : "+filetoDelete.getAbsolutePath());
}
}catch(IOException ex){
throw new IOException("Error in deleting file");
}
}
public static InputStream readFile(String completePathFile) throws IOException{
try{
File file = new File(completePathFile);
if(file.exists()){
InputStream in = new FileInputStream(file);
//byte myBytes[] = new byte[in.available()];
//in.read(myBytes);
//return new String(myBytes);
return in;
}else{
throw new IOException("FILE TO READ NOT FOUND !! pathFile : "+file.getAbsolutePath());
}
}catch(IOException ex){
throw new IOException("Error in reading file");
}
}
}