So I m trying to create a method through which I will upload a File.But while creating a new file in this method I need to use getBytes() method.But I get error saying.
The method getBytes() is undefined for the type File
How can I overcome this??.Below is my method.
public String SomeFile(File file, String basePath, UrlInfoKey urlInfoKey) {
LOG.info("basePath for back up is {}", basePath);
String uploadedPath = null;
String fileDetails = file.getName();
String locationDetails = fileDetails;
String locationFolderPath = basePath+"/"+locationDetails;
File directory = new File(locationFolderPath);
if(!directory.isDirectory()) {
LOG.info("creating the directory at {}", locationFolderPath);
directory.mkdir();
}
String filepath = locationFolderPath+"/"+file.getName().trim();
LOG.info("file path to back up is {}",filepath);
File creatingFile = new File(filepath);
try {
creatingFile.createNewFile();
FileOutputStream fos = new FileOutputStream(creatingFile);
fos.write(file.getBytes());
fos.close();
uploadedPath = filepath;
} catch (Exception e) {
LOG.info("could not create file ", e.getMessage());
}
uploadedPath= updateURLWithDBURL(urlInfoKey,uploadedPath);
LOG.info("file uploaded at location {}",uploadedPath);
return uploadedPath;
}
Line:fos.write(file.getBytes());
Is where I m getting error.Is there any other alternative I could use.Thanks in advance.