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:Main.java

public static void openFile(Context context, File url) throws IOException {
    // Create URI
    File file = url;/*from  ww  w  .  jav  a  2s  . c  o m*/
    Uri uri = Uri.fromFile(file);

    Intent intent = new Intent(Intent.ACTION_VIEW);
    // Check what kind of file you are trying to open, by comparing the url with extensions.
    // When the if condition is matched, plugin sets the correct intent (mime) type, 
    // so Android knew what application to use to open the file
    if (url.toString().contains(".doc") || url.toString().contains(".docx")) {
        // Word document
        intent.setDataAndType(uri, "application/msword");
    } else if (url.toString().contains(".pdf")) {
        // PDF file
        intent.setDataAndType(uri, "application/pdf");
    } else if (url.toString().contains(".ppt") || url.toString().contains(".pptx")) {
        // Powerpoint file
        intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
    } else if (url.toString().contains(".xls") || url.toString().contains(".xlsx")) {
        // Excel file
        intent.setDataAndType(uri, "application/vnd.ms-excel");
    } else if (url.toString().contains(".zip") || url.toString().contains(".rar")) {
        // WAV audio file
        intent.setDataAndType(uri, "application/zip");
    } else if (url.toString().contains(".rtf")) {
        // RTF file
        intent.setDataAndType(uri, "application/rtf");
    } else if (url.toString().contains(".wav") || url.toString().contains(".mp3")) {
        // WAV audio file
        intent.setDataAndType(uri, "audio/x-wav");
    } else if (url.toString().contains(".gif")) {
        // GIF file
        intent.setDataAndType(uri, "image/gif");
    } else if (url.toString().contains(".jpg") || url.toString().contains(".jpeg")
            || url.toString().contains(".png")) {
        // JPG file
        intent.setDataAndType(uri, "image/jpeg");
    } else if (url.toString().contains(".txt")) {
        // Text file
        intent.setDataAndType(uri, "text/plain");
    } else if (url.toString().contains(".3gp") || url.toString().contains(".mpg")
            || url.toString().contains(".mpeg") || url.toString().contains(".mpe")
            || url.toString().contains(".mp4") || url.toString().contains(".avi")) {
        // Video files
        intent.setDataAndType(uri, "video/*");
    } else {
        //if you want you can also define the intent type for any other file

        //additionally use else clause below, to manage other unknown extensions
        //in this case, Android will show all applications installed on the device
        //so you can choose which application to use
        intent.setDataAndType(uri, "*/*");
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:org.eclipse.virgo.ide.runtime.core.ServerUtils.java

/**
 * Returns the cache directory to be used by the {@link DependencyLocator}
 *///from  w  w  w.  j  a  v  a  2 s.co  m
private static String getCacheDirectoryPath() {
    // trying to generated a thread unique directory name
    File cacheDirectoryPath = new File(new StringBuilder(CACHE_LOCATION).append("-")
            .append(REPOSITORY_COUNTER.getAndIncrement()).toString());
    if (!cacheDirectoryPath.exists()) {
        cacheDirectoryPath.mkdirs();
    }
    return cacheDirectoryPath.toString();
}

From source file:Main.java

public static void openFileInExtApp(Context context, File url) throws IOException {
    // Create URI
    File file = url;//w w w  . j  av  a2 s .  co  m
    Uri uri = Uri.fromFile(file);

    Intent intent = new Intent(Intent.ACTION_VIEW);
    // Check what kind of file you are trying to open, by comparing the url with extensions.
    // When the if condition is matched, plugin sets the correct intent (mime) type,
    // so Android knew what application to use to open the file
    if (url.toString().contains(".doc") || url.toString().contains(".docx")) {
        // Word document
        intent.setDataAndType(uri, "application/msword");
    } else if (url.toString().contains(".pdf")) {
        // PDF file
        intent.setDataAndType(uri, "application/pdf");
    } else if (url.toString().contains(".ppt") || url.toString().contains(".pptx")) {
        // Powerpoint file
        intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
    } else if (url.toString().contains(".xls") || url.toString().contains(".xlsx")) {
        // Excel file
        intent.setDataAndType(uri, "application/vnd.ms-excel");
    } else if (url.toString().contains(".zip") || url.toString().contains(".rar")) {
        // WAV audio file
        intent.setDataAndType(uri, "application/x-wav");
    } else if (url.toString().contains(".rtf")) {
        // RTF file
        intent.setDataAndType(uri, "application/rtf");
    } else if (url.toString().contains(".wav") || url.toString().contains(".mp3")) {
        // WAV audio file
        intent.setDataAndType(uri, "audio/x-wav");
    } else if (url.toString().contains(".gif")) {
        // GIF file
        intent.setDataAndType(uri, "image/gif");
    } else if (url.toString().contains(".jpg") || url.toString().contains(".jpeg")
            || url.toString().contains(".png")) {
        // JPG file
        intent.setDataAndType(uri, "image/jpeg");
    } else if (url.toString().contains(".txt")) {
        // Text file
        intent.setDataAndType(uri, "text/plain");
    } else if (url.toString().contains(".html")) {
        // Html file
        intent.setDataAndType(uri, "text/html");
    } else if (url.toString().contains(".3gp") || url.toString().contains(".mpg")
            || url.toString().contains(".mpeg") || url.toString().contains(".mpe")
            || url.toString().contains(".mp4") || url.toString().contains(".avi")) {
        // Video files
        intent.setDataAndType(uri, "video/*");
    } else {
        //if you want you can also define the intent type for any other file

        //additionally use else clause below, to manage other unknown extensions
        //in this case, Android will show all applications installed on the device
        //so you can choose which application to use
        intent.setDataAndType(uri, "*/*");
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:net.morimekta.idltool.IdlUtils.java

public static File findRepoRc(File workingDir, boolean recursive) throws IOException {
    if (workingDir == null) {
        throw new IllegalArgumentException("No working directory");
    }/*from ww w. java  2s  . c  o m*/
    if (!workingDir.exists()) {
        throw new IOException("No such directory: " + workingDir.toString());
    }
    if (!workingDir.isDirectory()) {
        throw new IOException("No RC location not a directory: " + workingDir.toString());
    }

    File pwd = workingDir;
    File rc = new File(pwd, ".idlrc");
    if (recursive) {
        while (!rc.exists()) {
            pwd = pwd.getParentFile();
            if (pwd == null) {
                throw new IOException("No .idlrc file at: " + workingDir.getAbsolutePath() + " (recursive)");
            }
            rc = new File(pwd, ".idlrc");
        }
    }
    if (!rc.exists()) {
        throw new IOException("No .idlrc file at: " + workingDir.getAbsolutePath());
    }
    if (!rc.isFile()) {
        throw new IOException("Found .idlrc is not a file: " + pwd.getAbsolutePath());
    }
    return rc;
}

From source file:org.hupo.psi.mi.psicquic.ws.IndexBasedPsicquicServiceTest.java

@BeforeClass
public static void beforeClass() throws Exception {
    InputStream mitabStream = IndexBasedPsicquicServiceTest.class
            .getResourceAsStream("/META-INF/brca2.mitab.txt");
    File indexDir = new File("target", "brca-mitab.index");

    Searcher.buildIndex(indexDir, mitabStream, true, true);

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "/META-INF/beans.spring.test.xml" });
    PsicquicConfig config = (PsicquicConfig) context.getBean("psicquicConfig");
    config.setIndexDirectory(indexDir.toString());

    service = (IndexBasedPsicquicService) context.getBean("indexBasedPsicquicService");
}

From source file:net.ftb.util.FileUtils.java

public static void move(File oldFile, File newFile) {
    try {/*from   w w  w . j a va 2  s .  co m*/
        if (oldFile.exists() && !newFile.exists()) {
            org.apache.commons.io.FileUtils.moveFile(oldFile, newFile);
        }
    } catch (IOException e) {
        Logger.logWarn("Exception occurred while moving " + oldFile.toString() + " : " + e.getMessage());
    }
}

From source file:com.CodeSeance.JSeance.CodeGenXML.XMLElements.Template.java

public static String run(File templateFile, File includesDir, File modelsDir, File targetDir,
        boolean ignoreReadOnlyOuputFiles, TemplateDependencies templateDependencies) {
    // Create a local logger for the static context
    Log log = com.CodeSeance.JSeance.CodeGenXML.Runtime.CreateLogger(Template.class);

    if (log.isInfoEnabled()) {
        log.info(String.format("Loading Template:[%s]", templateFile.toString()));
    }/*  w  ww  .  ja v a 2  s.com*/

    // Load the default schema validator
    XMLLoader xmlLoader = XMLLoader.buildFromCodeTemplateSchema();

    // Loads the XML document
    Document document;
    try {
        InputStream inputStream = new FileInputStream(templateFile);
        document = xmlLoader.loadXML(inputStream);
    } catch (FileNotFoundException ex) {
        throw new RuntimeException(ExecutionError.INVALID_TEMPLATE_FILE.getMessage(templateFile.toString()),
                ex);
    } catch (SAXException ex) {
        throw new RuntimeException(
                ExecutionError.INVALID_TEMPLATE_XML.getMessage(templateFile.toString(), ex.getMessage()), ex);
    }

    // Load the object hierarchy from the XMLDocument
    Template template = new Template(document.getDocumentElement());

    if (log.isInfoEnabled()) {
        log.info("XMLSchema validated");
    }

    // Create a new ContextManager
    ContextManager contextManager = new ContextManager(includesDir, modelsDir, targetDir,
            ignoreReadOnlyOuputFiles, templateDependencies);

    try {
        // Enter and leave the context on the new template element
        template.onContextEnter(contextManager.getCurrentContext());
        template.onContextExit(contextManager.getCurrentContext());
    } finally {
        // dispose the context manager to release used resources
        contextManager.dispose();
    }

    return template.buffer.toString();
}

From source file:mSearch.tool.Log.java

public static synchronized void setLogfile(String logFileString) {
    logFile = new File(logFileString);
    File dir = new File(logFile.getParent());
    if (!dir.exists()) {
        if (!dir.mkdirs()) {
            logFile = null;/*w ww  .jav a2  s . c  o  m*/
            Log.errorLog(632012165, "Kann den Pfad nicht anlegen: " + dir.toString());
        }
    }

}

From source file:Main.java

/**
 * Method to split the path components of a file into a List
 * @param f the file to split//from  w ww. j  av  a  2 s . co  m
 * @return a new list containing the components of the path as strings
 */
protected static List<String> splitPath(File f) {
    List<String> result;
    File parent = f.getParentFile();
    if (parent == null) {
        result = new ArrayList<String>();
        if (f.getName().length() > 0) {
            // We're at the root but have a name so we have a relative path
            // for which we need to add the first component to the list
            result.add(f.getName());
        } else if (IS_WINDOWS) {
            String strF = f.toString();
            if (strF.matches(WINDOWS_DRIVE_ROOT_REGEX)) {
                // We're on windows and the path is <Drive>:\ so we
                // add the <Drive>: to the list
                result.add(strF.substring(0, strF.length() - 1).toUpperCase());
            }
        }
    } else {
        result = splitPath(parent);
        result.add(f.getName());
    }
    return result;
}

From source file:com.googlecode.fannj.FannTest.java

public static File build(File res) throws IOException {
    File temp = createTemp(res);
    List<Layer> layers = new ArrayList<Layer>();
    layers.add(Layer.create(2));//  w  ww  . j  a v a 2 s  .  c o m
    layers.add(Layer.create(3, ActivationFunction.FANN_SIGMOID_SYMMETRIC));
    layers.add(Layer.create(1, ActivationFunction.FANN_SIGMOID_SYMMETRIC));
    Fann fann = new Fann(layers);
    Trainer trainer = new Trainer(fann);
    float desiredError = .001f;
    @SuppressWarnings("unused")
    float mse = trainer.train(temp.getPath(), 500000, 1000, desiredError);
    fann.save(temp.toString());
    assertEquals(0, fann.getErrno());
    return temp;
}