Java Utililty Methods File Object Create

List of utility methods to do File Object Create

  1. HOME
  2. Java
  3. F
  4. File Object Create

Description

The list of methods to do File Object Create are organized into topic(s).

Method

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 baseDir, String path)
to File
File result = baseDir;
for (String part : path.split("/")) { 
 result = new File(result, part);
return result;
File toFile(File currentDirectory, String file)
to File
String f = file == null ? "" : file;
if (f.startsWith("/")) {
 return new File(f);
return new File(currentDirectory, f);
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;
int toFile(InputStream in, File file)
to File
try (FileOutputStream out = new FileOutputStream(file)) {
 return copyStream(in, out);
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) {
...


AltStyle によって変換されたページ (->オリジナル) /