The list of methods to do File Object Create are organized into topic(s).
void
toFile(byte[] bFile) to File
try {
FileOutputStream fileOuputStream = new FileOutputStream("C:\\testing2.png");
fileOuputStream.write(bFile);
fileOuputStream.close();
System.out.println("Done");
} catch (Exception e) {
e.printStackTrace();
File
toFile(Class> cls) to File
return new File(cls.getName().replace('.', '/') + ".class");
File
toFile(File dir, String[] path) Build a full path of file with given directory, and relative path.
String dirPath = dir.getCanonicalPath();
StringBuilder sb = new StringBuilder(dirPath);
for (int i = 0; i < path.length; i++) {
sb.append(File.separator);
sb.append(path[i]);
return new File(sb.toString());
File
toFile(File dstPath, String fullClassName) Converts file reference from file and ensures that the path exists
String packageName = getPackageName(fullClassName);
String packagePath = packageName.replaceAll("\\.", "/");
File path = new File(dstPath, packagePath);
path.mkdirs();
if (!path.exists())
throw new RuntimeException("Could not create " + path);
String fileName = fullClassName.replaceAll("\\.", "/");
File file = new File(dstPath, fileName + ".java");
...
void
toFile(File file, byte[] data) Outputs some arbitrary data to file on disk
System.out.println("Attempt create file " + file.getAbsolutePath());
File parent = file.getParentFile();
parent.mkdirs();
BufferedOutputStream outputStream = null;
try {
outputStream = new BufferedOutputStream(new FileOutputStream(file));
outputStream.write(data);
} catch (FileNotFoundException e) {
...
File
toFile(IFile file) to File
File f = file.getRawLocation() != null ? file.getRawLocation().toFile() : null;
if (f == null)
f = file.getLocation() != null ? file.getLocation().toFile() : null;
if (f == null)
f = file.getFullPath() != null ? file.getFullPath().toFile() : null;
return f;
File
toFile(InputStream inputStream) to File
File result = null;
OutputStream outputStream = null;
try {
result = File.createTempFile(".tmp", ".tmp");
outputStream = new FileOutputStream(result);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
...