Java Code Examples for java.io.File.toString()

The following are Jave code examples for showing how to use toString() of the java.io.File class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ExamesGithub   File: MainActivity.java   View Source Code Vote up 6 votes
private void openFileBrowser() {

        //Selecting the "EXAMES_APP" Folder as default
        File root = android.os.Environment.getExternalStorageDirectory();
        File dir = new File(root.getAbsolutePath() + "/Exames-App/");
        String directoryy = dir.toString();

        //Giving the FilePicker a custom Title:
        String title = "Selecione um dos Exames";

        new MaterialFilePicker()
                .withActivity(MainActivity.this)
                .withRequestCode(1)
                .withFilter(Pattern.compile(".*\\.pdf$"))
                .withFilterDirectories(false) // Set directories filterable (false by default)
                .withHiddenFiles(false) // Show hidden files and folders
                .withRootPath(directoryy)
                .withTitle(title)
                .start();
    }
 
Example 2
Project: youkes_browser   File: BrowserActivity.java   View Source Code Vote up 6 votes
private void longClickPageFiles(String url) {

		File bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME);
		String bookmarkUrl=Constants.FILE + bookmarkWebPage.toString();
		LightningView lv=getCurrentWebView();
		if(lv==null){
			return;
		}
		String webUrl=lv.getUrl();
		if(webUrl.equalsIgnoreCase(bookmarkUrl)){
			openBookmarkUrlLongClick(url);
			return;
		}

		File historyWebPage = new File(this.getFilesDir(), "history.html");
		String historyUrl= Constants.FILE + historyWebPage;
		if(webUrl.equalsIgnoreCase(historyUrl)){
			openHistoryUrlLongClick(url);
			return;
		}
	}
 
Example 3
Project: browser   File: BrowserActivity.java   View Source Code Vote up 6 votes
private void longClickPageFiles(String url) {

		File bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME);
		String bookmarkUrl=Constants.FILE + bookmarkWebPage.toString();
		LightningView lv=getCurrentWebView();
		if(lv==null){
			return;
		}
		String webUrl=lv.getUrl();
		if(webUrl.equalsIgnoreCase(bookmarkUrl)){
			openBookmarkUrlLongClick(url);
			return;
		}

		File historyWebPage = new File(this.getFilesDir(), "history.html");
		String historyUrl= Constants.FILE + historyWebPage;
		if(webUrl.equalsIgnoreCase(historyUrl)){
			openHistoryUrlLongClick(url);
			return;
		}
	}
 
Example 4
Project: n4js   File: N4HeadlessCompiler.java   View Source Code Vote up 6 votes
/**
 * Collects the projects containing the given single source files.
 *
 * @param sourceFiles
 *            the list of single source files
 * @return list of N4JS project locations
 * @throws N4JSCompileException
 *             if no project cannot be found for one of the given files
 */
private List<File> findProjectsForSingleFiles(List<File> sourceFiles)
		throws N4JSCompileException {

	Set<URI> result = Sets.newLinkedHashSet();

	for (File sourceFile : sourceFiles) {
		URI sourceFileURI = URI.createFileURI(sourceFile.toString());
		URI projectURI = n4jsFileBasedWorkspace.findProjectWith(sourceFileURI);
		if (projectURI == null) {
			throw new N4JSCompileException("No project for file '" + sourceFile.toString() + "' found.");
		}
		result.add(projectURI);
	}

	// convert back to Files:
	return result.stream().map(u -> new File(u.toFileString())).collect(Collectors.toList());
}
 
Example 5
Project: Ultraino   File: MainForm.java   View Source Code Vote up 6 votes
private void onExit(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_onExit
    try {
        //snap config
        final File f =  FileUtils.getLastChooserPath();
        if (f != null){
            config.lastPath = f.toString();
        }
        
        //try to save config
        FileUtils.writeObject(new File(CONFIG_PATH), config);
    } catch (Exception ex) {
        Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
    }
    
    System.exit(0);
}
 
Example 6
Project: tg-qq-trans   File: CreateConfigs.java   View Source Code Vote up 5 votes
public static void createConfigs(File configFile)
{
	
	ConfigData configData = new ConfigData();
	configData.coolqDir = "./coolq";
	configData.qqBotPort = 11235;
	configData.qqBotNumber = "10000";
	configData.telegramBotToken = "";
	GroupsPairs sample = new GroupsPairs();
	sample.qqGroup = 10000;
	sample.telegramGroup = -1;
	configData.groupsPairs = new ArrayList<GroupsPairs>();
	configData.groupsPairs.add(sample);
	configData.proxyConfig = new ProxyConfig();
	configData.proxyConfig.enableProxy = false;
	configData.proxyConfig.proxyType = "SOCKS";
	configData.proxyConfig.proxyHost = "127.0.0.1";
	configData.proxyConfig.proxyPort = 1080;
	configData.enabledPlugins = new ArrayList<String>();
	configData.enabledPlugins.add("plugins.Transport");
	
	Gson gson = new GsonBuilder().setPrettyPrinting().create();
	String JSONString = gson.toJson(configData);
	
	try
	{
		FileWriter out = new FileWriter(configFile.toString());
		out.write(JSONString);
		out.close();
	}
	catch(IOException e)
	{
		e.printStackTrace();
	}
}
 
Example 7
Project: gradle-circle-style   File: FailuresReportGenerator.java   View Source Code Vote up 5 votes
private static String getClassName(File file) {
    Matcher matcher = JAVA_FILE_RX.matcher(file.toString());
    if (matcher.matches()) {
        return matcher.group(1).replace('/', '.');
    }
    return file.toString();
}
 
Example 8
Project: incubator-netbeans   File: GenerateJnlpFileTask.java   View Source Code Vote up 5 votes
/** 
 * Returns true is file has the same name as one of the JARs marked for
 * indirect inclusion through separate jnlp component instead of directly.
 * @param file
 * @param extJars
 * @return true if file is not to be included in main jnlp directly
 */
private static boolean isExternalJar(File file, Set<? extends String> extJars) {
    if(file != null && extJars != null) {
        String fileStr = file.toString();
        for(String extJar : extJars) {
            if(fileStr.contains(extJar)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 9
Project: Transwarp-Sample-Code   File: SuperPut.java   View Source Code Vote up 5 votes
/**
 * 将文件夹中文件添加到队列中
 * @param folders 需要上传文件的文件夹集合
 */
public static void addFiles(String[] folders) {
    String[] file_types = constant.FILE_TYPE_FILTER.split(",");
    for (String folder : folders) {
        File file = new File(folder);
        File[] files = file.listFiles();
        if (files != null) {
            for (File f : files) {
                String s1 = f.toString();
                if (!f.isDirectory() && !s1.contains("COMPLETED_")) {
                    for (String s2 : file_types) {
                        int l1 = s1.length();
                        int l2 = s2.length();
                        String s3 = s1.substring(l1-l2,l1);
                        if (s3.equals(s2)) {
                            try {
                                blockingQueue.put(s1);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 10
Project: OneClient   File: FileHash.java   View Source Code Vote up 5 votes
public FileHash(File file) {
	this.file = file.toString();
	try {
		this.hash = getFileChecksum(file);
	} catch (IOException e) {
		OneClientLogging.error("{} {}", file, e);
	}
}
 
Example 11
Project: incubator-netbeans   File: FixImportsTest.java   View Source Code Vote up 5 votes
/**
 * Sets up logging facilities.
 */
@Override
public void setUp() {
    System.out.println("########  "+getName()+"  #######");
    err = getLog();
    log = getRef();
    JemmyProperties.getProperties().setOutput(new TestOut(null,
            new PrintWriter(err, true), new PrintWriter(err, false), null));
    try {
        File wd = getWorkDir();
        workDir = wd.toString();
    } catch (IOException e) { }
    openDefaultProject();
}
 
Example 12
Project: manifold   File: ManFileExt.java   View Source Code Vote up 5 votes
/**
 * Adds [relative] file to this, considering this as a directory.
 * If [relative] has a root, [relative] is returned back.
 * For instance, `File("/foo/bar").resolve(File("gav"))` is `File("/foo/bar/gav")`.
 * This function is complementary with [relativeTo],
 * so `f.resolve(g.relativeTo(f)) == g` should be always `true` except for different roots case.
 *
 * @return concatenated this and [relative] paths, or just [relative] if it's absolute.
 */
public static File resolve( @This File thiz, File relative )
{
  if( relative.isRooted() )
  {
    return relative;
  }
  String baseName = thiz.toString();
  return baseName.isEmpty() || baseName.endsWith( File.separator )
         ? new File( baseName + relative )
         : new File( baseName + File.separatorChar + relative );
}
 
Example 13
Project: litiengine   File: Map.java   View Source Code Vote up 5 votes
public String save(String fileName) {
  if (fileName == null || fileName.isEmpty()) {
    return null;
  }

  String fileNameWithExtension = fileName;
  if (!fileNameWithExtension.endsWith("." + FILE_EXTENSION)) {
    fileNameWithExtension += "." + FILE_EXTENSION;
  }

  File newFile = new File(fileNameWithExtension);

  try (FileOutputStream fileOut = new FileOutputStream(newFile)) {
    JAXBContext jaxbContext = JAXBContext.newInstance(Map.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);

    final ByteArrayOutputStream out = new ByteArrayOutputStream();

    // first: marshal to byte array
    jaxbMarshaller.marshal(this, out);
    out.flush();

    // second: postprocess xml and then write it to the file
    XmlUtilities.saveWithCustomIndetation(new ByteArrayInputStream(out.toByteArray()), fileOut, 1);
    out.close();

    jaxbMarshaller.marshal(this, out);
  } catch (JAXBException | IOException e) {
    log.log(Level.SEVERE, e.getMessage(), e);
  }

  return newFile.toString();
}
 
Example 14
Project: hadoop   File: TestLocalContainerLauncher.java   View Source Code Vote up 5 votes
@BeforeClass
public static void setupTestDirs() throws IOException {
  testWorkDir = new File("target",
      TestLocalContainerLauncher.class.getCanonicalName());
  testWorkDir.delete();
  testWorkDir.mkdirs();
  testWorkDir = testWorkDir.getAbsoluteFile();
  for (int i = 0; i < localDirs.length; i++) {
    final File dir = new File(testWorkDir, "local-" + i);
    dir.mkdirs();
    localDirs[i] = dir.toString();
  }
}
 
Example 15
Project: OpenJSharp   File: ClassLoaderHelper.java   View Source Code Vote up 5 votes
/**
 * Returns an alternate path name for the given file
 * such that if the original pathname did not exist, then the
 * file may be located at the alternate location.
 * For mac, this replaces the final .dylib suffix with .jnilib
 */
static File mapAlternativeName(File lib) {
    if (!ikvm.internal.Util.MACOSX) {
        return null;
    }
    String name = lib.toString();
    int index = name.lastIndexOf('.');
    if (index < 0) {
        return null;
    }
    return new File(name.substring(0, index) + ".jnilib");
}
 
Example 16
Project: Equella   File: Office2HtmlConversionServiceImpl.java   View Source Code Vote up 5 votes
@SuppressWarnings("nls")
@PostConstruct
public void setupBinaries()
{
	if( disableConversion )
	{
		return;
	}

	// Test for the Java install
	File javaBinDir = new File(javaHome, "bin");
	if( !javaBinDir.exists() || !javaBinDir.isDirectory() )
	{
		throw new RuntimeException(
			"Error setting conversionService.javaPath: Java directory not found at " + javaBinDir);
	}

	File javaExeFile = ExecUtils.findExe(javaBinDir, "java");
	if( javaExeFile == null )
	{
		throw new RuntimeException(
			"Error setting conversionService.javaPath: Java executable not found in " + javaBinDir);
	}

	this.javaExe = javaExeFile.toString();

	// Test for the conversion service
	File cjFile = new File(conversionJar);
	if( !cjFile.exists() || cjFile.isDirectory() )
	{
		throw new RuntimeException(
			"Error setting conversionService.conversionServicePath: Conversion service JAR does not exist at "
				+ cjFile);
	}
	this.conversionDir = cjFile.getParentFile();
}
 
Example 17
Project: hadoop-oss   File: TestGenericOptionsParser.java   View Source Code Vote up 4 votes
public void testFilesOption() throws Exception {
  File tmpFile = new File(testDir, "tmpfile");
  Path tmpPath = new Path(tmpFile.toString());
  localFs.create(tmpPath);
  String[] args = new String[2];
  // pass a files option 
  args[0] = "-files";
  // Convert a file to a URI as File.toString() is not a valid URI on
  // all platforms and GenericOptionsParser accepts only valid URIs
  args[1] = tmpFile.toURI().toString();
  new GenericOptionsParser(conf, args);
  String files = conf.get("tmpfiles");
  assertNotNull("files is null", files);
  assertEquals("files option does not match",
    localFs.makeQualified(tmpPath).toString(), files);
  
  // pass file as uri
  Configuration conf1 = new Configuration();
  URI tmpURI = new URI(tmpFile.toURI().toString() + "#link");
  args[0] = "-files";
  args[1] = tmpURI.toString();
  new GenericOptionsParser(conf1, args);
  files = conf1.get("tmpfiles");
  assertNotNull("files is null", files);
  assertEquals("files option does not match", 
    localFs.makeQualified(new Path(tmpURI)).toString(), files);
 
  // pass a file that does not exist.
  // GenericOptionParser should throw exception
  Configuration conf2 = new Configuration();
  args[0] = "-files";
  args[1] = "file:///xyz.txt";
  Throwable th = null;
  try {
    new GenericOptionsParser(conf2, args);
  } catch (Exception e) {
    th = e;
  }
  assertNotNull("throwable is null", th);
  assertTrue("FileNotFoundException is not thrown",
    th instanceof FileNotFoundException);
  files = conf2.get("tmpfiles");
  assertNull("files is not null", files);
}
 
Example 18
Project: aliyun-maxcompute-data-collectors   File: TestHiveImport.java   View Source Code Vote up 4 votes
/**
 * Test hive import with row that has new line in it.
 */
@Test
public void testFieldWithHiveDelims() throws IOException,
  InterruptedException {
  final String TABLE_NAME = "FIELD_WITH_NL_HIVE_IMPORT";

  LOG.info("Doing import of single row into FIELD_WITH_NL_HIVE_IMPORT table");
  setCurTableName(TABLE_NAME);
  setNumCols(3);
  String[] types = getTypesNewLineTest();
  String[] vals = { "'test with \n new lines \n'", "42",
      "'oh no " + '\01' + " field delims " + '\01' + "'", };
  String[] moreArgs = { "--"+ BaseSqoopTool.HIVE_DROP_DELIMS_ARG };

  runImportTest(TABLE_NAME, types, vals, "fieldWithNewlineImport.q",
      getArgv(false, moreArgs), new ImportTool());

  LOG.info("Validating data in single row is present in: "
        + "FIELD_WITH_NL_HIVE_IMPORT table");

  // Ideally, we would actually invoke hive code to verify that record with
  // record and field delimiters have values replaced and that we have the
  // proper number of hive records. Unfortunately, this is a non-trivial task,
  // and better dealt with at an integration test level
  //
  // Instead, this assumes the path of the generated table and just validate
  // map job output.

  // Get and read the raw output file
  String whDir = getWarehouseDir();
  File p = new File(new File(whDir, TABLE_NAME), "part-m-00000");
  File f = new File(p.toString());
  FileReader fr = new FileReader(f);
  BufferedReader br = new BufferedReader(fr);
  try {
    // verify the output
    assertEquals(br.readLine(), "test with  new lines " + '\01' + "42"
        + '\01' + "oh no  field delims ");
    assertEquals(br.readLine(), null); // should only be one line
  } catch (IOException ioe) {
    fail("Unable to read files generated from hive");
  } finally {
    br.close();
  }
}
 
Example 19
Project: Jenisys3   File: Config.java   View Source Code Vote up 4 votes
public Config(File file, int type) {
    this(file.toString(), type, new ConfigSection());
}
 
Example 20
Project: Nukkit-Java9   File: Config.java   View Source Code Vote up 4 votes
@Deprecated
public Config(File file, int type, LinkedHashMap<String, Object> defaultMap) {
    this(file.toString(), type, new ConfigSection(defaultMap));
}