Tabnine Logo
File.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
java.io.File
constructor

Best Java code snippets using java.io.File.<init> (Showing top 20 results out of 207,954)

Refine searchRefine arrow

  • File.exists
  • PrintStream.println
  • File.getAbsolutePath
  • FileOutputStream.<init>
  • FileInputStream.<init>
  • File.mkdirs
  • File.isDirectory
  • FileOutputStream.close
origin: iluwatar/java-design-patterns

/**
 * @return True, if the file given exists, false otherwise.
 */
public boolean fileExists() {
 return new File(this.fileName).exists();
}
origin: stackoverflow.com

 File f = new File(filePathString);
if(f.exists() && !f.isDirectory()) { 
  // do something
}
origin: stackoverflow.com

 // create a File object for the parent directory
File wallpaperDirectory = new File("/sdcard/Wallpaper/");
// have the object build the directory structure, if needed.
wallpaperDirectory.mkdirs();
// create a File object for the output file
File outputFile = new File(wallpaperDirectory, filename);
// now attach the OutputStream to the file object, instead of a String representation
FileOutputStream fos = new FileOutputStream(outputFile);
origin: libgdx/libgdx

private void copyAndReplace (String outputDir, Project project, Map<String, String> values) {
  File out = new File(outputDir);
  if (!out.exists() && !out.mkdirs()) {
    throw new RuntimeException("Couldn't create output directory '" + out.getAbsolutePath() + "'");
  }
  for (ProjectFile file : project.files) {
    copyFile(file, out, values);
  }
}
origin: apache/incubator-dubbo

resolveFile = System.getProperty("dubbo.resolve.file");
if (StringUtils.isEmpty(resolveFile)) {
  File userResolveFile = new File(new File(System.getProperty("user.home")), "dubbo-resolve.properties");
  if (userResolveFile.exists()) {
    resolveFile = userResolveFile.getAbsolutePath();
  try (FileInputStream fis = new FileInputStream(new File(resolveFile))) {
    properties.load(fis);
  } catch (IOException e) {
origin: stanfordnlp/CoreNLP

private void save(String path) throws IOException {
 System.out.print("Saving classifier to " + path + "... ");
 // make sure the directory specified by path exists
 int lastSlash = path.lastIndexOf(File.separator);
 if (lastSlash > 0) {
  File dir = new File(path.substring(0, lastSlash));
  if (! dir.exists())
   dir.mkdirs();
 }
 ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(path));
 out.writeObject(weights);
 out.writeObject(featureIndex);
 out.writeObject(labelIndex);
 out.close();
 System.out.println("done.");
}
origin: androidannotations/androidannotations

private File ensureOutputDirectory() {
  File outputDir = new File(OUTPUT_DIRECTORY);
  if (!outputDir.exists()) {
    outputDir.mkdirs();
  }
  return outputDir;
}
origin: stackoverflow.com

 String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() + 
              "/PhysicsSketchpad";
  File dir = new File(file_path);
if(!dir.exists())
  dir.mkdirs();
  File file = new File(dir, "sketchpad" + pad.t_id + ".png");
  FileOutputStream fOut = new FileOutputStream(file);

  bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut);
  fOut.flush();
  fOut.close();
origin: stackoverflow.com

 File theDir = new File("new folder");

// if the directory does not exist, create it
if (!theDir.exists()) {
  System.out.println("creating directory: " + directoryName);
  boolean result = false;

  try{
    theDir.mkdir();
    result = true;
  } 
  catch(SecurityException se){
    //handle it
  }        
  if(result) {    
    System.out.println("DIR created");  
  }
}
origin: stackoverflow.com

 File imgFile = new  File("/sdcard/Images/test_image.jpg");

if(imgFile.exists()){

  Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

  ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);

  myImage.setImageBitmap(myBitmap);

}
origin: apache/incubator-druid

@Before
public void setUp() throws IOException
{
 cgroupDir = temporaryFolder.newFolder();
 procDir = temporaryFolder.newFolder();
 TestUtils.setUpCgroups(procDir, cgroupDir);
 cpuacctDir = new File(
   cgroupDir,
   "cpu,cpuacct/system.slice/some.service/f12ba7e0-fa16-462e-bb9d-652ccc27f0ee"
 );
 Assert.assertTrue((cpuacctDir.isDirectory() && cpuacctDir.exists()) || cpuacctDir.mkdirs());
 TestUtils.copyResource("/cpuacct.usage_all", new File(cpuacctDir, "cpuacct.usage_all"));
}
origin: eclipse-vertx/vert.x

private File setupFile(String testDir, String fileName, String content) throws Exception {
 File file = new File(testDir, fileName);
 if (file.exists()) {
  file.delete();
 }
 BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
 out.write(content);
 out.close();
 return file;
}
origin: stackoverflow.com

 ByteArrayOutputStream bytes = new ByteArrayOutputStream();
_bitmapScaled.compress(Bitmap.CompressFormat.JPEG, 40, bytes);

//you can create a new file name "test.jpg" in sdcard folder.
File f = new File(Environment.getExternalStorageDirectory()
            + File.separator + "test.jpg");
f.createNewFile();
//write the bytes in file
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());

// remember close de FileOutput
fo.close();
origin: square/okhttp

public void run() throws Exception {
 File file = new File("README.md");
 Request request = new Request.Builder()
   .url("https://api.github.com/markdown/raw")
   .post(RequestBody.create(MEDIA_TYPE_MARKDOWN, file))
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  System.out.println(response.body().string());
 }
}
origin: Tencent/tinker

private static void setRunningLocation(CliMain m) {
  mRunningLocation = m.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
  try {
    mRunningLocation = URLDecoder.decode(mRunningLocation, "utf-8");
  } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
  }
  if (mRunningLocation.endsWith(".jar")) {
    mRunningLocation = mRunningLocation.substring(0, mRunningLocation.lastIndexOf(File.separator) + 1);
  }
  File f = new File(mRunningLocation);
  mRunningLocation = f.getAbsolutePath();
}
origin: alibaba/druid

  private InputStream getFileAsStream(String filePath) throws FileNotFoundException {
    InputStream inStream = null;
    File file = new File(filePath);
    if (file.exists()) {
      inStream = new FileInputStream(file);
    } else {
      inStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
    }
    return inStream;
  }
}
origin: stackoverflow.com

 File folder = new File("your/path");
File[] listOfFiles = folder.listFiles();

  for (int i = 0; i < listOfFiles.length; i++) {
   if (listOfFiles[i].isFile()) {
    System.out.println("File " + listOfFiles[i].getName());
   } else if (listOfFiles[i].isDirectory()) {
    System.out.println("Directory " + listOfFiles[i].getName());
   }
  }
origin: stackoverflow.com

 File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/dir1/dir2");
dir.mkdirs();
File file = new File(dir, "filename");

FileOutputStream f = new FileOutputStream(file);
...
origin: skylot/jadx

  private Object test(Object obj) {
    File file = new File("r");
    FileOutputStream output = null;
    try {
      output = new FileOutputStream(file);
      if (obj.equals("a")) {
        return new Object();
      } else {
        return null;
      }
    } catch (IOException e) {
      System.out.println("Exception");
      return null;
    } finally {
      if (output != null) {
        try {
          output.close();
        } catch (IOException e) {
          // Ignored
        }
      }
      file.delete();
    }
  }
}
origin: skylot/jadx

  private Object test(Object obj) {
    FileOutputStream output = null;
    try {
      output = new FileOutputStream(new File("f"));
      return new Object();
    } catch (FileNotFoundException e) {
      System.out.println("Exception");
      return null;
    }
  }
}
java.ioFile<init>

Javadoc

Constructs a new file using the specified directory and name.

Popular methods of File

  • exists
    Tests whether the file or directory denoted by this abstract pathname exists.
  • getAbsolutePath
    Returns the absolute pathname string of this abstract pathname. If this abstract pathname is already
  • getName
    Returns the name of the file or directory denoted by this abstract pathname. This is just the last n
  • isDirectory
  • mkdirs
  • delete
    Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a director
  • listFiles
    Returns an array of abstract pathnames denoting the files and directories in the directory denoted b
  • getParentFile
    Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not
  • getPath
    Converts this abstract pathname into a pathname string. The resulting string uses the #separator to
  • isFile
  • length
    Returns the length of the file denoted by this abstract pathname. The return value is unspecified if
  • toURI
  • length,
  • toURI,
  • createTempFile,
  • createNewFile,
  • toPath,
  • mkdir,
  • lastModified,
  • toString,
  • getCanonicalPath

Popular in Java

  • Running tasks concurrently on multiple threads
  • findViewById (Activity)
  • setRequestProperty (URLConnection)
  • getSharedPreferences (Context)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • JLabel (javax.swing)
  • JOptionPane (javax.swing)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now