当前位置: 首页>>代码示例>>Java>>正文


Java Path.toString方法代码示例

本文整理汇总了Java中java.nio.file.Path.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Path.toString方法的具体用法?Java Path.toString怎么用?Java Path.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.Path的用法示例。


在下文中一共展示了Path.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSymlinkDirList

import java.nio.file.Path; //导入方法依赖的package包/类
@Test
public void testSymlinkDirList() throws Exception {
    FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
    Path path = fs.getPath("/packages/java.lang/java.base");
    assertTrue(Files.isSymbolicLink(path));
    assertTrue(Files.isDirectory(path));

    boolean javaSeen = false, javaxSeen = false;
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
        for (Path p : stream) {
            String str = p.toString();
            if (str.endsWith("/java")) {
                javaSeen = true;
            } else if (str.endsWith("javax")) {
                javaxSeen = true;
            }
        }
    }
    assertTrue(javaSeen);
    assertTrue(javaxSeen);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:Basic.java

示例2: getFileName

import java.nio.file.Path; //导入方法依赖的package包/类
public static String getFileName(final Path path)
{
    String result = null;
 
    if (path != null)
    {
        try
        {
            result = path.toRealPath(LinkOption.NOFOLLOW_LINKS).toString();
        }
        catch (final IOException ioe)
        {
            result = path.toString();
        }
    }
    
    return result;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:19,代码来源:FileUtils.java

示例3: handleFileUpload

import java.nio.file.Path; //导入方法依赖的package包/类
private String handleFileUpload(final MultipartFile file, final String outFileName, final String rootPath) throws IOException {
    final File parentDir = new File(rootPath);
    if (!parentDir.exists() && !parentDir.mkdirs()) {
        throw new IOException("Failed to createConsumer directory: " + rootPath);
    }

    // Create final output file name
    final Path fullOutputPath = Paths.get(rootPath, outFileName);
    if (fullOutputPath.toFile().exists()) {
        throw new IOException("Output file already exists");
    }

    // Get the file and save it somewhere
    final byte[] bytes = file.getBytes();
    Files.write(fullOutputPath, bytes);

    return fullOutputPath.toString();
}
 
开发者ID:SourceLabOrg,项目名称:kafka-webview,代码行数:19,代码来源:UploadManager.java

示例4: loadResource

import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public void loadResource(IosCredentialDetail detail, Path tmp) {
    Path zipPath = Paths.get(tmp.toString() + ZIP_SUFFIX);
    File targetFile = new File(zipPath.toString());

    try {
        for (PasswordFileResource passwordFileResource : detail.getP12s()) {
            FileUtils.copyFileToDirectory(Paths.get(passwordFileResource.getPath()).toFile(), tmp.toFile());
        }

        for (FileResource fileResource : detail.getProvisionProfiles()) {
            FileUtils.copyFileToDirectory(Paths.get(fileResource.getPath()).toFile(), tmp.toFile());
        }

        ZipUtil.zipFolder(tmp.toFile(), targetFile);
    } catch (IOException e) {
        throw new FlowException("Io exception " + ExceptionUtil.findRootCause(e));
    }
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:20,代码来源:CredentialServiceImpl.java

示例5: search

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * search.
 * @param path - path
 * @param fileName - fileName
 */
public void search(Path path, String fileName) {
    File file = new File(path.toString());
    File[] folders = file.listFiles();
    fileName = prepMask(fileName);

    if (folders != null) {
        for (File f : folders) {
            if (f.isDirectory()) {
                search(Paths.get(f.toString()), fileName);
                continue;
            } else {
                if (f.getName().contains(fileName)) {
                    list.append(f.toString());
                    list.append(System.getProperty("line.separator"));
                }
            }
        }
    }
}
 
开发者ID:istolbov,项目名称:i_stolbov,代码行数:25,代码来源:SearchEngine.java

示例6: testPut

import java.nio.file.Path; //导入方法依赖的package包/类
@Test
public void testPut() throws URISyntaxException, IOException  {

	Path SRC = Paths.get(ClassLoader.getSystemResource("TestFileConnectors/test.xml").toURI());
	File srcFile = new File(SRC.toString());
	assertTrue(srcFile.exists());
	filePutConnector.setRequest(srcFile);
	
	String destPath=System.getProperty("java.io.tmpdir")+File.separator+
			ConfigurationHolder.configuration().getString(filePutConnector.getName() + Constants.FILE_PATH_KEY); 
	filePutConnector.setDestPath(destPath);
	filePutConnector.proceed();
	File resFile = new File(destPath);
	assertTrue(resFile.exists());
	assertTrue(Files.equal(srcFile, resFile));
	

}
 
开发者ID:rockitconsulting,项目名称:test.rockitizer,代码行数:19,代码来源:FilePutConnectorTest.java

示例7: handleFolderData

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Method returning all information about file/folder of given path
 * @param request REST obtained request - needed param "path"
 * @param response REST regived response
 * @return FolderMetadata or FileMetadata object
 */
public Object handleFolderData(Request request, Response response) {

    Path path = Paths.get(request.params("path"));
    FolderMetadata result = null;
    try{
        result = folderMetadataDao.fetchByPathLower(path.toString()).get(0);
        return result;
    }catch(Exception e){
        try{
            FileMetadata foundedFile = null;
            foundedFile = fileMetadataDao.fetchByPathLower(path.toString()).get(0);
            return foundedFile;
        }catch (Exception ex){
            throw new InvalidPathException(path.toString());
        }
    }
}
 
开发者ID:Ewastachow,项目名称:java-rest-server,代码行数:24,代码来源:FileController.java

示例8: copy

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Copies given file to a given destination directory.
 * @param src Source file path.
 * @param dest Destination path.
 * @throws IOException Error with copying.
 */
private void copy(Path src, Path dest) throws IOException {
	FileInputStream inputStream = new FileInputStream(src.toString());
	FileOutputStream outputStream = new FileOutputStream(dest.toString());

	byte[] inputBuffer = new byte[4096];
	int bytesRead;
	while ((bytesRead = inputStream.read(inputBuffer)) > 0) {
		outputStream.write(inputBuffer, 0, bytesRead);
	}
	inputStream.close();
	outputStream.close();
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:19,代码来源:CopyShellCommand.java

示例9: makeClassName

import java.nio.file.Path; //导入方法依赖的package包/类
static String makeClassName(Path path) {
    String fileName = path.toString();

    if (!fileName.endsWith(".class")) {
        throw new IllegalArgumentException("File doesn't end with .class: '" + fileName + "'");
    }

    fileName = stripRoot(path);

    String className = fileName.substring(0, fileName.length() - ".class".length());
    className = className.replace(path.getFileSystem().getSeparator(), ".");
    return className;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ClassSource.java

示例10: LogFilter

import java.nio.file.Path; //导入方法依赖的package包/类
private LogFilter(Path file, Pattern logPattern,
        String defaultEntry, String lineSeparator,
        Map<String, Predicate<String>> namedGroupFilters,
        int maxEntries, boolean keepFirst)
        throws FileNotFoundException
{
    this.file = requireNonNull(file);
    this.logPattern = requireNonNull(logPattern);
    this.defaultEntry = requireNonNull(defaultEntry);
    this.lineSeparator = requireNonNull(lineSeparator);
    this.namedGroupFilters = ImmutableMap.copyOf(requireNonNull(namedGroupFilters));
    this.maxEntries = maxEntries;
    this.keepFirst = keepFirst;
    if (!Files.isRegularFile(file)) {
        throw new FileNotFoundException(file.toString());
    }

    Matcher matcher = logPattern.matcher(defaultEntry);
    if (!matcher.matches()) {
        throw new IllegalArgumentException(
                "Default entry does not match log entry pattern");
    }
    try {
        for (Map.Entry<String, Predicate<String>> f
                : namedGroupFilters.entrySet()) {
            matcher.group(f.getKey());
        }
    }
    catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
                "Invalid capturing group in log filter", e);
    }
}
 
开发者ID:prestodb,项目名称:presto-manager,代码行数:34,代码来源:LogFilter.java

示例11: isValid

import java.nio.file.Path; //导入方法依赖的package包/类
private boolean isValid(Path fileName) {
    if (fileName == null) {
        return true;
    } else {
        String name = fileName.toString();
        if (name.endsWith("/")) {
            name = name.substring(0, name.length() - 1);
        }
        return SourceVersion.isIdentifier(name);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:JavacFileManager.java

示例12: deleteRecursively

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Deletes the file or directory at the given {@code path} recursively. Deletes symbolic links,
 * not their targets (subject to the caveat below).
 *
 * <p>If an I/O exception occurs attempting to read, open or delete any file under the given
 * directory, this method skips that file and continues. All such exceptions are collected and,
 * after attempting to delete all files, an {@code IOException} is thrown containing those
 * exceptions as {@linkplain Throwable#getSuppressed() suppressed exceptions}.
 *
 * <h2>Warning: Security of recursive deletes</h2>
 *
 * <p>On a file system that supports symbolic links and does <i>not</i> support
 * {@link SecureDirectoryStream}, it is possible for a recursive delete to delete files and
 * directories that are <i>outside</i> the directory being deleted. This can happen if, after
 * checking that a file is a directory (and not a symbolic link), that directory is replaced by a
 * symbolic link to an outside directory before the call that opens the directory to read its
 * entries.
 *
 * <p>By default, this method throws {@link InsecureRecursiveDeleteException} if it can't
 * guarantee the security of recursive deletes. If you wish to allow the recursive deletes
 * anyway, pass {@link RecursiveDeleteOption#ALLOW_INSECURE} to this method to override that
 * behavior.
 *
 * @throws NoSuchFileException if {@code path} does not exist <i>(optional specific
 *     exception)</i>
 * @throws InsecureRecursiveDeleteException if the security of recursive deletes can't be
 *     guaranteed for the file system and {@link RecursiveDeleteOption#ALLOW_INSECURE} was not
 *     specified
 * @throws IOException if {@code path} or any file in the subtree rooted at it can't be deleted
 *     for any reason
 */
public static void deleteRecursively(
    Path path, RecursiveDeleteOption... options) throws IOException {
  Path parentPath = getParentPath(path);
  if (parentPath == null) {
    throw new FileSystemException(path.toString(), null, "can't delete recursively");
  }

  Collection<IOException> exceptions = null; // created lazily if needed
  try {
    boolean sdsSupported = false;
    try (DirectoryStream<Path> parent = Files.newDirectoryStream(parentPath)) {
      if (parent instanceof SecureDirectoryStream) {
        sdsSupported = true;
        exceptions = deleteRecursivelySecure(
            (SecureDirectoryStream<Path>) parent, path.getFileName());
      }
    }

    if (!sdsSupported) {
      checkAllowsInsecure(path, options);
      exceptions = deleteRecursivelyInsecure(path);
    }
  } catch (IOException e) {
    if (exceptions == null) {
      throw e;
    } else {
      exceptions.add(e);
    }
  }

  if (exceptions != null) {
    throwDeleteFailed(path, exceptions);
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:66,代码来源:MoreFiles.java

示例13: getGlobValues

import java.nio.file.Path; //导入方法依赖的package包/类
private static List<String> getGlobValues(String arg, boolean absolute) throws IOException {
	List<String> result = new ArrayList<String>();
	Path dir = new File(arg).toPath();
	try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "glob:" + arg)) {
		for (Path path : stream) {
			Path pathValue = absolute ? path.toAbsolutePath() : path.getFileName();
			String value = pathValue.toString();
			result.add(value);
		}
	}
	return result;
}
 
开发者ID:Bibliome,项目名称:bibliome-java-utils,代码行数:13,代码来源:ProductPatternSpecificationBuilder.java

示例14: getLocales

import java.nio.file.Path; //导入方法依赖的package包/类
private ArrayList<LocaleVO> getLocales() throws Exception {
	URI uri = LocaleList.class.getResource("/locales").toURI();
	Path myPath = null;
	boolean inJar = false;
	if (uri.getScheme().equals("jar")) {
		FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.<String, Object>emptyMap());
		myPath = fileSystem.getPath("/locales");
		inJar = true;
	} else {
		myPath = Paths.get(uri);
	}
	ArrayList<LocaleVO> localeList = new ArrayList<>();
	try (Stream<Path> walk = Files.walk(myPath, 1)) {
		for (Iterator<Path> it = walk.iterator(); it.hasNext();) {
			Path next = it.next();
			String name = next.toString();
			if (!inJar) {
				File file = next.toFile();
				name = "/" + file.getName();
			}
			if (!name.equals("/locales") && !name.contains("/locale.properties")) {
				String localeName = name.replaceAll(".properties", "");
				localeName = localeName.replaceAll("/locales/", "");
				localeName = localeName.replaceAll("/", "");
				localeName = localeName.replaceAll("locale_", "");
				LocaleVO localeVO = new LocaleVO(localeName);
				localeList.add(localeVO);
			}
		}
	} catch (Exception e) {
		System.out.println(e.getMessage());
	}
	Collections.sort(localeList);
	return localeList;
}
 
开发者ID:SoapboxRaceWorld,项目名称:soapbox-race-jlauncher,代码行数:36,代码来源:LocaleList.java

示例15: main

import java.nio.file.Path; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable {
    Path srcDir = Paths.get(System.getProperty("test.src"));
    Path targetDir = Paths.get(System.getProperty("user.dir"));
    Path jar1SrcDir = srcDir.resolve("src").resolve("jar1");
    Path jar1TargetDir =  targetDir.resolve("jar1");
    Path ectJar1Dir = srcDir.resolve("etc").resolve("jar1");
    Path jarFile = targetDir.resolve("jar1.jar");
    Path[]  files= new Path[] {
            Paths.get("res1.txt"), Paths.get("jar1", "bundle.properties")
    };

    // Copy files to target directory and change permission
    for (Path file : files) {
        Path dest = jar1TargetDir.resolve(file);
        Files.createDirectories(dest.getParent());
        Files.copy(ectJar1Dir.resolve(file), dest, REPLACE_EXISTING);
    }

    // Compile and build jar1.jar
    ProcessTools.executeCommand("chmod", "-R", "u+w", "./jar1")
                .outputTo(System.out)
                .errorTo(System.out)
                .shouldHaveExitValue(0);
    CompilerUtils.compile(jar1SrcDir, jar1TargetDir);
    JarUtils.createJarFile(jarFile, jar1TargetDir);

    // Compile test files
    CompilerUtils.compile(srcDir.resolve("src").resolve("test"), targetDir);

    // Run tests
    String java = JDKToolFinder.getTestJDKTool("java");
    String cp = targetDir.toString() + File.pathSeparator + jarFile;
    String[] tests = new String[]{"TestBug4361044", "TestBug4523159"};
    for (String test : tests) {
        ProcessTools.executeCommand(java, "-cp", cp, test)
                    .outputTo(System.out)
                    .errorTo(System.out)
                    .shouldHaveExitValue(0);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:TestDriver.java


注:本文中的java.nio.file.Path.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。