Created
August 26, 2011 07:23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
/** | |
* Created by IntelliJ IDEA. | |
* User: victor | |
* Date: 8/26/11 | |
* Time: 12:26 AM | |
* To change this template use File | Settings | File Templates. | |
*/ | |
public class FileUtils { | |
public String uploadFile(String name, String directory, byte[] content){ | |
File file = new File(directory); | |
if(!file.exists()){ | |
file.mkdir(); | |
} | |
name = directory + "/" + name; | |
File fileToUpload = new File(name); | |
try{ | |
FileOutputStream fos = new FileOutputStream(fileToUpload); | |
fos.write(content); | |
fos.close(); | |
}catch(IOException ex){ | |
Logger.getLogger(FileUtils.class.getSimpleName()).log(Level.SEVERE, ex.getMessage()); | |
return "File not uploaded"; | |
} | |
return "File uploaded"; | |
} | |
public byte[] getFile(String fullName){ | |
byte[] output = null; | |
File file = new File(fullName); | |
if(file.exists()){ | |
output = new byte[(int)file.length()]; | |
try{ | |
FileInputStream fis = new FileInputStream(file); | |
fis.read(output); | |
fis.close(); | |
}catch(IOException ex){ | |
Logger.getLogger(FileUtils.class.getSimpleName()).log(Level.SEVERE, ex.getMessage()); | |
} | |
} | |
return output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment