Example usage for java.io File toString

List of usage examples for java.io File toString

Introduction

In this page you can find the example usage for java.io File toString.

Prototype

public String toString() 

Source Link

Document

Returns the pathname string of this abstract pathname.

Usage

From source file:net.chunkyhosting.Roe.CHGManagerLauncher.utils.JSON.java

public static void writeJsonToFile(JSONObject json, File file) throws IOException {

    FileWriter writer = new FileWriter(file.toString());

    try {//from w w  w.jav a  2  s . c om

        writer.write(json.toString(4));

    } finally {

        writer.flush();
        writer.close();

    }

}

From source file:io.fabric8.vertx.maven.plugin.FileFilterMain.java

private static FileAlterationMonitor fileWatcher(Set<Path> inclDirs) {
    FileAlterationMonitor monitor = new FileAlterationMonitor(1000);

    inclDirs.forEach(path -> {//  w ww. java2 s. c o m
        System.out.println("Adding Observer to " + path.toString());
        FileAlterationObserver observer = new FileAlterationObserver(path.toFile());
        observer.addListener(new FileAlterationListenerAdaptor() {
            @Override
            public void onFileCreate(File file) {
                System.out.println("File Create:" + file.toString());
            }

            @Override
            public void onFileChange(File file) {
                System.out.println("File Change:" + file.toString());
            }

            @Override
            public void onFileDelete(File file) {
                System.out.println("File Delete:" + file.toString());
            }

        });
        monitor.addObserver(observer);
    });

    return monitor;

}

From source file:Main.java

public static String getDownloadDir() {
    String status = Environment.getExternalStorageState();
    if (status == null || !status.equals(Environment.MEDIA_MOUNTED)) {
        return null;
    }//  w w  w . j ava  2 s  .c  o m

    String path = null;

    // get the sdcard directory
    File sdFile = Environment.getExternalStorageDirectory();
    if (null != sdFile) {
        path = sdFile.toString();
    } else {
        path = "/sdcard/";
    }

    path += "/download";

    File destDir = new File(path);
    if (!destDir.exists()) {
        try {
            if (!destDir.mkdirs()) {
                Log.e("getDownloadDir", "create folder " + path + " failed");
                return null;
            }
        } catch (SecurityException e) {
            Log.e("getDownloadDir", "create folder " + path + " failed: " + e.toString());
            return null;
        }
    }

    return path;
}

From source file:com.splunk.shuttl.testutil.TUtilsTestNG.java

/**
 * Asserts that the contents of specified files are equal. Failing the test
 * with specified message if not./*from w ww.  j  a  v  a 2  s. c o  m*/
 */
public static void assertFileContentsEqual(String message, File expected, File actual) {
    assertTrue(expected.toString() + " doesn't exist.", expected.exists());
    assertTrue(actual.toString() + " doesn't exist.", actual.exists());
    message = message == null ? "" : message;

    try {
        assertTrue(message, FileUtils.contentEquals(expected, actual));
    } catch (IOException e) {
        failForException("Can't compare contents of files.", e);
    }
}

From source file:Main.java

public static File savebitmap(Bitmap bitmap) {
    OutputStream outStream = null;
    File folder = new File(Environment.getExternalStorageDirectory().toString() + "/InSyte");
    folder.mkdirs();//from  ww w  .j av a2 s  .com
    String mDirectory = folder.toString();
    File file = new File(mDirectory, "IMG_" + System.currentTimeMillis() + ".jpg");
    try {
        outStream = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
        outStream.flush();
        outStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return file;

}

From source file:com.phoenixnap.oss.ramlapisync.plugin.ClassLoaderUtils.java

public static List<String> loadPackages(MavenProject mavenProject) throws MojoExecutionException {

    List<String> packages = Lists.newArrayList();

    logger.info("Loading packages in " + mavenProject.getBuild().getSourceDirectory() + "...");
    File rootDir = new File(mavenProject.getBuild().getSourceDirectory() + "//");
    Collection<File> files = FileUtils.listFilesAndDirs(rootDir, DirectoryFileFilter.DIRECTORY,
            TrueFileFilter.TRUE);//from ww  w . jav a  2s  . c  o m
    for (File file : files) {
        String pack = file.toString().replace(rootDir.toString(), "").replace(File.separator, ".");
        if (pack.startsWith(".")) {
            pack = pack.substring(1, pack.length());
        }
        if (!pack.isEmpty()) {
            packages.add(pack);
        }
    }

    return packages;
}

From source file:net.skyebook.zerocollada.ZeroCollada.java

private static File newFilename(File file, ColladaManipulator manipulator) {
    return new File(file.toString().substring(0, file.toString().lastIndexOf("."))
            + manipulator.newFileNameSuffix() + ".dae");
}

From source file:Main.java

/**
 * @throws IOException if {@code f} does not exists.
 *//*from w w w .j  a va 2  s . c o m*/
public static void validateExists(File f) throws IOException {
    if (!f.exists()) {
        throw new IOException(
                String.format("Error: %s doesn't exist, please choose another file\n", f.toString()));
    }
}

From source file:Main.java

/**
 * Return the original MIME type of the given file, using the DRM framework
 * if the file is protected content./*w w  w .j  av  a 2s  .c  om*/
 */
public static String getOriginalMimeType(Context context, File file, String currentMime) {
    final DrmManagerClient client = new DrmManagerClient(context);
    try {
        final String rawFile = file.toString();
        if (client.canHandle(rawFile, null)) {
            return client.getOriginalMimeType(rawFile);
        } else {
            return currentMime;
        }
    } finally {
        client.release();
    }
}

From source file:Main.java

public static void createCSV() {
    File folder = new File(Environment.getExternalStorageDirectory() + "/adspammer");
    if (!folder.exists())
        folder.mkdir();/*from www.  j a  v a  2 s  .  com*/

    String filename = folder.toString() + "/" + "log.csv";

    File csvFile = new File(filename);
    if (!csvFile.exists())
        try {
            csvFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }

}