java.io.File.toString()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中java.io.File.toString()方法的一些代码示例,展示了File.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.toString()方法的具体详情如下:
包路径:java.io.File
类名称:File
方法名:toString

File.toString介绍

[英]Returns a string containing a concise, human-readable description of this file.
[中]返回一个字符串,其中包含此文件的简明易读描述。

代码示例

代码示例来源:origin: stackoverflow.com

ImageView.setImageURI(Uri.parse(new File("/sdcard/cats.jpg").toString()));

代码示例来源:origin: apache/zookeeper

private void doFailForNonExistingPath(File file) {
  if (!file.exists()) {
    throw new IllegalArgumentException(file.toString()
        + " file is missing");
  }
}

代码示例来源:origin: apache/storm

/**
 * Ensure the existence of a given directory.
 *
 * @throws IOException if it cannot be created and does not already exist
 */
private static void ensureDirectory(File dir) throws IOException {
  if (!dir.mkdirs() && !dir.isDirectory()) {
    throw new IOException("Mkdirs failed to create " +
               dir.toString());
  }
}

代码示例来源:origin: FudanNLP/fnlp

public static void main(String[] args) throws Exception {
  String input1 ="D:/Datasets/sighan2006/processed";
  
  File f = new File(input1);
  if (f.isDirectory()) {
    File[] files = f.listFiles();
    for (int i = 0; i < files.length; i++) {
      processLabeledData(files[i].toString(),"utf8","gbk");
    }
  }
  System.out.println("Done");
}

代码示例来源:origin: androidannotations/androidannotations

private File findManifestInSpecifiedPath(String androidManifestPath) throws FileNotFoundException {
  File androidManifestFile = new File(androidManifestPath);
  if (!androidManifestFile.exists()) {
    LOGGER.error("Could not find the AndroidManifest.xml file in specified path : {}", androidManifestPath);
    throw new FileNotFoundException();
  } else {
    LOGGER.debug("AndroidManifest.xml file found with specified path: {}", androidManifestFile.toString());
  }
  return androidManifestFile;
}

代码示例来源:origin: apache/incubator-gobblin

@BeforeClass
public void setUp() throws Exception {
 this.eventBus.register(this);
 // Prepare the test url to download the job conf from
 final URL url = GobblinAWSClusterLauncherTest.class.getClassLoader().getResource(JOB_FIRST_ZIP);
 final String jobConfZipUri = getJobConfigZipUri(new File(url.toURI()));
 // Prepare the test dir to download the job conf to
 if (this.jobConfigFileDir.exists()) {
  FileUtils.deleteDirectory(this.jobConfigFileDir);
 }
 Assert.assertTrue(this.jobConfigFileDir.mkdirs(), "Failed to create " + this.jobConfigFileDir);
 final Config config = getConfig(jobConfZipUri)
     .withValue(GobblinClusterConfigurationKeys.JOB_CONF_PATH_KEY, ConfigValueFactory.fromAnyRef(this.jobConfigFileDir.toString()))
     .withValue(GobblinAWSConfigurationKeys.JOB_CONF_REFRESH_INTERVAL, ConfigValueFactory.fromAnyRef("10s"));
 this.jobConfigurationManager = new AWSJobConfigurationManager(this.eventBus, config);
 this.jobConfigurationManager.startAsync().awaitRunning();
}

代码示例来源:origin: ReactiveX/RxJava

URL u = MaybeNo2Dot0Since.class.getResource(MaybeNo2Dot0Since.class.getSimpleName() + ".class");
String path = new File(u.toURI()).toString().replace('\\', '/');
  System.out.println("Can't find the base RxJava directory");
  return null;
File f = new File(p);
  System.out.println("Can't read " + p);
  return null;

代码示例来源:origin: spring-projects/spring-loaded

public static String findJar(String whereToLook, String jarPrefix) {
  File dir = new File(whereToLook);
  File[] fs = dir.listFiles();
  for (File f : fs) {
    if (f.getName().startsWith(jarPrefix)) {
      return f.toString();
    }
  }
  return null;
}

代码示例来源:origin: libgdx/libgdx

System.out.println("Processing tileset " + tilesetName);
        System.out.println("Stripped id #" + gid + " from tileset \"" + tilesetName + "\"");
      System.out.println("Adding " + tileWidth + "x" + tileHeight + " (" + (int)tileLocation.x + ", "
        + (int)tileLocation.y + ")");
String tilesetOutputDir = outputDir.toString() + "/" + this.settings.tilesetOutputDirectory;
File relativeTilesetOutputDir = new File(tilesetOutputDir);
File outputDirTilesets = new File(relativeTilesetOutputDir.getCanonicalPath());
outputDirTilesets.mkdirs();
packer.pack(outputDirTilesets, this.settings.atlasOutputName + ".atlas");

代码示例来源:origin: cSploit/android

public static synchronized void errorLogging(Throwable e) {
 String message = "Unknown error.",
     trace = "Unknown trace.",
     filename = (new File(Environment.getExternalStorageDirectory().toString(), ERROR_LOG_FILENAME)).getAbsolutePath();
 if (e != null) {
  if (e.getMessage() != null && !e.getMessage().isEmpty())
   message = e.getMessage();
  else if (e.toString() != null)
   message = e.toString();
  if (message.equals(mLastError))
   return;
  Writer sWriter = new StringWriter();
  PrintWriter pWriter = new PrintWriter(sWriter);
  e.printStackTrace(pWriter);
  trace = sWriter.toString();
  if (mContext != null && getSettings().getBoolean("PREF_DEBUG_ERROR_LOGGING", false)) {
   try {
    FileWriter fWriter = new FileWriter(filename, true);
    BufferedWriter bWriter = new BufferedWriter(fWriter);
    bWriter.write(trace);
    bWriter.close();
   } catch (IOException ioe) {
    Logger.error(ioe.toString());
   }
  }
 }
 setLastError(message);
 Logger.error(message);
 Logger.error(trace);
}

代码示例来源:origin: stackoverflow.com

// snippet taken from question
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
path = new File(path, "SubDirName");
path.mkdirs();

// initiate media scan and put the new things into the path array to
// make the scanner aware of the location and the files you want to see
MediaScannerConnection.scanFile(this, new String[] {path.toString()}, null, null);

代码示例来源:origin: alibaba/jstorm

InputStream in = zipFile.getInputStream(entry);
try {
  File file = new File(unzipDir, entry.getName());
  if (!file.getParentFile().mkdirs()) {
    if (!file.getParentFile().isDirectory()) {
      throw new IOException("Mkdirs failed to create " +
          file.getParentFile().toString());

代码示例来源:origin: apache/incubator-pinot

/**
 * @param segmentDirectory File pointing to segment directory
 * @param metadata segment metadata. Metadata must be fully initialized
 * @param readMode mmap vs heap map mode
 */
protected ColumnIndexDirectory(File segmentDirectory, SegmentMetadataImpl metadata, ReadMode readMode) {
 Preconditions.checkNotNull(segmentDirectory);
 Preconditions.checkNotNull(readMode);
 Preconditions.checkNotNull(metadata);
 Preconditions.checkArgument(segmentDirectory.exists(),
   "SegmentDirectory: " + segmentDirectory.toString() + " does not exist");
 Preconditions.checkArgument(segmentDirectory.isDirectory(),
   "SegmentDirectory: " + segmentDirectory.toString() + " is not a directory");
 this.segmentDirectory = segmentDirectory;
 this.metadata = metadata;
 this.readMode = readMode;
}

代码示例来源:origin: spotbugs/spotbugs

private static void loadPluginsInDir(File pluginDir, boolean optional) {
  File[] contentList = pluginDir.listFiles();
  if (contentList == null) {
    return;
  }
  for (File file : contentList) {
    if (file.getName().endsWith(".jar")) {
      try {
        URL url = file.toURI().toURL();
        if (IO.verifyURL(url)) {
          loadInitialPlugin(url, true, optional);
          if (FindBugs.DEBUG) {
            System.out.println("Found plugin: " + file.toString());
          }
        }
      } catch (MalformedURLException e) {
      }
    }
  }
}

代码示例来源:origin: apache/hbase

String javaCode = code != null ? code : "public class " + className + " {}";
Path srcDir = new Path(testDir, "src");
File srcDirPath = new File(srcDir.toString());
srcDirPath.mkdirs();
File sourceCodeFile = new File(srcDir.toString(), className + ".java");
BufferedWriter bw = Files.newBufferedWriter(sourceCodeFile.toPath(), StandardCharsets.UTF_8);
bw.write(javaCode);
srcFileNames.add(sourceCodeFile.toString());
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null,
 null);
String currentDir = new File(".").getAbsolutePath();
String classpath = currentDir + File.separator + "target"+ File.separator
 + "classes" + System.getProperty("path.separator")
File jarFile = new File(folder, jarFileName);
jarFile.getParentFile().mkdirs();
if (!createJarArchive(jarFile,
  new File[]{new File(srcDir.toString(), className + ".class")})){

代码示例来源:origin: pentaho/pentaho-kettle

private static void createTempDirWithSpecialCharactersInName() throws IOException {
 if ( !TEMP_DIR_WITH_REP_FILE.exists() ) {
  if ( TEMP_DIR_WITH_REP_FILE.mkdir() ) {
   System.out.println( "CREATED: " + TEMP_DIR_WITH_REP_FILE.getCanonicalPath() );
  } else {
   System.out.println( "NOT CREATED: " + TEMP_DIR_WITH_REP_FILE.toString() );
  }
 }
}

代码示例来源:origin: redisson/redisson

if (!file.exists()) {
  throw new FileNotFoundException(file.toString());
  path = file.getName();
boolean isDir = file.isDirectory();
if (recursive && file.isDirectory()) {
  boolean noRelativePath = StringUtil.isEmpty(path);
      String childRelativePath = (noRelativePath ? StringPool.EMPTY : path) + child.getName();
      addToZip(zos, child, childRelativePath, comment, recursive);

代码示例来源:origin: stanfordnlp/CoreNLP

public void initLog(File logFilePath) throws IOException {
 RedwoodConfiguration.empty()
  .handlers(RedwoodConfiguration.Handlers.chain(
   RedwoodConfiguration.Handlers.showAllChannels(), RedwoodConfiguration.Handlers.stderr),
   RedwoodConfiguration.Handlers.file(logFilePath.toString())
  ).apply();
 // fh.setFormatter(new NewlineLogFormatter());
 System.out.println("Starting Ssurgeon log, at "+logFilePath.getAbsolutePath()+" date=" + DateFormat.getDateInstance(DateFormat.FULL).format(new Date()));
 log.info("Starting Ssurgeon log, date=" + DateFormat.getDateInstance(DateFormat.FULL).format(new Date()));
}

代码示例来源:origin: FudanNLP/fnlp

/**
 * @param fileName
 */
public void read(String fileName) {
  File f = new File(fileName);
  if (f.isDirectory()) {
    File[] files = f.listFiles();
    for (int i = 0; i < files.length; i++) {
      read(files[i].toString());
    }
  } else {
    try {
      InputStreamReader read = new InputStreamReader(
          new FileInputStream(fileName), "utf-8");
      BufferedReader bin = new BufferedReader(read);
      String sent;
      while ((sent = bin.readLine()) != null) {
        calc(sent);
      }
    } catch (Exception e) {
    }
  }
}

代码示例来源:origin: jeremylong/DependencyCheck

/**
 * Deletes any files extracted from the JAR during analysis.
 */
@Override
public void closeAnalyzer() {
  if (tempFileLocation != null && tempFileLocation.exists()) {
    LOGGER.debug("Attempting to delete temporary files from `{}`", tempFileLocation.toString());
    final boolean success = FileUtils.delete(tempFileLocation);
    if (!success && tempFileLocation.exists()) {
      final String[] l = tempFileLocation.list();
      if (l != null && l.length > 0) {
        LOGGER.warn("Failed to delete the JAR Analyzder's temporary files from `{}`, "
            + "see the log for more details", tempFileLocation.getAbsolutePath());
      }
    }
  }
}

相关文章

微信公众号

最新文章

更多