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


Java File.toPath方法代码示例

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


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

示例1: SingleFileBucket

import java.io.File; //导入方法依赖的package包/类
SingleFileBucket(long bucketNumber, long bucketSize, Encryption encryption, File file) {
    this.bucketSize = bucketSize;
    this.bucketNumber = bucketNumber;
    this.encryption = encryption;
    baseOffset = bucketNumber * this.bucketSize;
    upperBound = baseOffset + this.bucketSize - 1;
    LOGGER.debug("starting to monitor bucket {} with file {}", bucketNumber, file.getAbsolutePath());
    this.file = file;
    try {
        filePath = file.toPath();
        final long existingFileSize = Files.size(filePath);
        this.fileWasZero = existingFileSize == 0;
        lastModifiedTime = Files.getLastModifiedTime(filePath);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:MineboxOS,项目名称:minebox,代码行数:18,代码来源:SingleFileBucket.java

示例2: BaseWatcher

import java.io.File; //导入方法依赖的package包/类
public BaseWatcher ( final StorageManager storageManager, final File base ) throws IOException
{
    this.storageManager = storageManager;
    this.base = base.toPath ();
    this.watcher = FileSystems.getDefault ().newWatchService ();

    this.baseKey = base.toPath ().register ( this.watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE );

    logger.debug ( "Checking for initial storages" );

    for ( final File child : this.base.toFile ().listFiles () )
    {
        logger.debug ( "Found initial storage dir - {}", child );
        checkAddStorage ( child.toPath () );
    }

    startWatcher ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:BaseWatcher.java

示例3: getTempFile

import java.io.File; //导入方法依赖的package包/类
static Path getTempFile(int size) throws IOException {
    File f = File.createTempFile("test", "txt");
    f.deleteOnExit();
    byte[] buf = new byte[2048];
    for (int i=0; i<buf.length; i++)
        buf[i] = (byte)i;

    FileOutputStream fos = new FileOutputStream(f);
    while (size > 0) {
        int amount = Math.min(size, buf.length);
        fos.write(buf, 0, amount);
        size -= amount;
    }
    fos.close();
    return f.toPath();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:SmokeTest.java

示例4: isRemoteFS

import java.io.File; //导入方法依赖的package包/类
private static boolean isRemoteFS (FileObject fo) {
    if (!CHECK_REMOTE_FSTYPES) {
        return false;
    }
    if (!fo.isFolder()) {
        return false;
    }
    final File f = FileUtil.toFile(fo);
    if (f == null) {
        return false;
    }
    final Path p = f.toPath();
    try {
        final String fsType = Files.getFileStore(p).type();
        return REMOTE_FSTYPES.contains(fsType);
    } catch (IOException ioe) {
        Exceptions.printStackTrace(ioe);
        return false;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:BaseFileObjectTestHid.java

示例5: setLastModifiedTime

import java.io.File; //导入方法依赖的package包/类
/**
 * altera o longtime da última modificação no arquivo
 *
 * @param time data no formato longtime
 */
public static void setLastModifiedTime(File file, long time) {
    try {
        Path path = file.toPath();
        FileTime fileTime = FileTime.fromMillis(time);
        Files.setLastModifiedTime(path, fileTime);
    } catch (IOException ex) {
    }
}
 
开发者ID:limagiran,项目名称:hearthstone,代码行数:14,代码来源:Dir.java

示例6: gson

import java.io.File; //导入方法依赖的package包/类
@Nonnull
public static GsonConfigurationLoader gson(@Nonnull File file) {
    Path path = file.toPath();
    return GsonConfigurationLoader.builder()
            .setIndent(2)
            .setSource(() -> Files.newBufferedReader(path, StandardCharsets.UTF_8))
            .setSink(() -> Files.newBufferedWriter(path, StandardCharsets.UTF_8))
            .build();
}
 
开发者ID:lucko,项目名称:helper,代码行数:10,代码来源:Configs.java

示例7: createIndexForFile

import java.io.File; //导入方法依赖的package包/类
/**
 * Creates index for a FeatureFile
 * @param featureFile a file to create index for
 * @return an index, represented by {@code SimpleFSDirectory} object
 * @throws IOException if something is wrong with access to file system
 */
public SimpleFSDirectory createIndexForFile(FeatureFile featureFile) throws IOException {
    final Map<String, Object> params = new HashMap<>();
    params.put(USER_ID.name(), featureFile.getCreatedBy());
    params.put(DIR_ID.name(), featureFile.getId());

    FilePathFormat format = determineFilePathFormat(featureFile);

    params.put(FEATURE_FILE_DIR.name(), substitute(format, params));
    File file = new File(toRealPath(substitute(FEATURE_INDEX_DIR, params)));

    return new SimpleFSDirectory(file.toPath());
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:19,代码来源:FileManager.java

示例8: createDirectory

import java.io.File; //导入方法依赖的package包/类
/**
 * Creates a new directory with the given parent folder and folder name. The newly created folder will be deleted on
 * graceful VM shutdown.
 *
 * @param parent
 *            the path of the parent folder.
 * @param folderName
 *            the name of the folder.
 * @return the path to the new directory.
 */
public static Path createDirectory(final Path parent, final String folderName) {
	final File file = new File(parent.toFile(), folderName);
	if (!file.exists()) {
		if (!file.mkdir()) {
			throw new RuntimeException(
					"Error while trying to create folder at " + parent + " with " + folderName + ".");
		}
	}
	file.deleteOnExit();
	return file.toPath();
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:22,代码来源:FileUtils.java

示例9: findProjectWith

import java.io.File; //导入方法依赖的package包/类
@Override
public URI findProjectWith(URI nestedLocation) {
	final String path = nestedLocation.toFileString();
	if (null == path) {
		return null;
	}

	final File nestedResource = new File(path);
	if (!nestedResource.exists()) {
		return null;
	}

	final Path nestedResourcePath = nestedResource.toPath();

	final Iterable<URI> registeredProjectUris = projectCache.asMap().keySet();
	for (final URI projectUri : registeredProjectUris) {
		if (projectUri.isFile()) {
			final File projectRoot = new File(projectUri.toFileString());
			final Path projectRootPath = projectRoot.toPath();
			if (nestedResourcePath.startsWith(projectRootPath)) {
				return projectUri;
			}
		}
	}

	return null;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:28,代码来源:EclipseExternalLibraryWorkspace.java

示例10: createIndexForProject

import java.io.File; //导入方法依赖的package包/类
/**
 * Creates a {@code SimpleFSDirectory} object, representing a new Lucene index directory for feature index for
 * desired project ID
 *
 * @param projectId     an ID of a project, which feature index directory to fetch
 * @return an {@code SimpleFSDirectory} object, representing Lucene index directory for feature index
 * @throws IOException if something is wrong with access to file system
 */
public SimpleFSDirectory createIndexForProject(final long projectId) throws IOException {
    final Map<String, Object> params = new HashMap<>();
    params.put(PROJECT_ID.name(), projectId);

    File file = new File(toRealPath(substitute(PROJECT_FEATURE_INDEX_FILE, params)));

    return new SimpleFSDirectory(file.toPath());
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:17,代码来源:FileManager.java

示例11: onSetup

import java.io.File; //导入方法依赖的package包/类
@Override
public void onSetup(File log, File world) {
    try {
      connection = new InjectionConnection(log.toPath(), world.toPath(), "jarbot");
    } catch (IOException | InterruptedException ex) {
      throw new UndeclaredThrowableException(ex);
    }
    connection.getLogObserver().setLogCheckFrequency(500, MILLISECONDS);
    connection.setFlushFrequency(500, MILLISECONDS);

    connection.getLogObserver().addChatListener(l -> {
        if(l.getMessage().charAt(0) != '.') answer(Jarbot.ask(l.getMessage()));
    });
}
 
开发者ID:Energyxxer,项目名称:Vanilla-Injection,代码行数:15,代码来源:ChatDemo.java

示例12: actionPerformed

import java.io.File; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e){
	System.out.println("Save As activated");
	GUI.fc.setCurrentDirectory(new File(gui.savePath));
	int returnVal = GUI.fc.showOpenDialog(new JFrame("Save As..."));
	String path = gui.savePath;
	
       if (returnVal == JFileChooser.APPROVE_OPTION) {
       	
           File file = GUI.fc.getSelectedFile();
           File _src = new File(path+"/"+filename.getText());
           Path src = _src.toPath();
           try {
			if( !_src.exists() ){
				return;
			} else {
				Path cop = file.toPath();
				Files.copy(src, cop, StandardCopyOption.REPLACE_EXISTING);
			}
		} catch (IOException e1) {
			e1.printStackTrace();
		}

       } else {
       }
	gui.refreshFileTree(gui.savePath);
	System.out.println("Done");
}
 
开发者ID:KayDeeTee,项目名称:Hollow-Knight-SaveManager,代码行数:29,代码来源:Listeners.java

示例13: getOtherRoots

import java.io.File; //导入方法依赖的package包/类
public File[] getOtherRoots(boolean test) {
    URI uri = FileUtilities.getDirURI(getProjectDirectory(), test ? "src/test" : "src/main"); //NOI18N
    Set<File> toRet = new HashSet<File>();
    File fil = Utilities.toFile(uri);
    if (fil.exists()) {
        try {
            Path sourceRoot = fil.toPath();
            OtherRootsVisitor visitor = new OtherRootsVisitor(getLookup(), sourceRoot);
            Files.walkFileTree(sourceRoot, visitor);
            toRet.addAll(visitor.getOtherRoots());
        } catch (IOException ex) {
            // log as info to keep trace about possible problems, 
            // but lets not be too agressive with level and notification                
            // see also issue #251071
            LOG.log(Level.INFO, null, ex);
        }
    }
    URI[] res = getResources(test);
    for (URI rs : res) {
        File fl = Utilities.toFile(rs);
        //in node view we need only the existing ones, if anything else needs all,
        // a new method is probably necessary..
        if (fl.exists()) {
            toRet.add(fl);
        }
    }
    return toRet.toArray(new File[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:NbMavenProjectImpl.java

示例14: findModuleInfo

import java.io.File; //导入方法依赖的package包/类
public MultiModuleGroupQuery.Result findModuleInfo(SourceGroup grp) {
    MultiModuleGroupQuery.Result res;
    
    synchronized (this) {
        res = cachedModuleInfo.get(grp);
        if (res != null) {
            return res == NONE ? null : res;
        }
    }
    int ver = version.get();
    Set<String> props = new HashSet<>();
    Set<FileObject> newmodRoots = new HashSet<>();
    for (Roots r : roots) {
        if (!RootsAccessor.getInstance().isSourceRoot(r)) {
            continue;
        }
        FileObject groot = grp.getRootFolder();
        File rootFile = FileUtil.toFile(groot);
        Path rootPath = rootFile.toPath();
        String[] propNames = r.getRootProperties();
        String[] rootPathPropNames = RootsAccessor.getInstance().getRootPathProperties(r);
        for (int i = 0; i < propNames.length; i++) {
            final String prop = propNames[i];
            final String pathProp = rootPathPropNames[i];
            final String type = RootsAccessor.getInstance().getType(r);

            if (pathProp == null || JavaProjectConstants.SOURCES_TYPE_MODULES.equals(type)) {  //NOI18N
                continue;
            }
            final String pathToModules = evaluator.getProperty(prop);
            final String loc = evaluator.getProperty(pathProp);
            final File file = helper.resolveFile(pathToModules);
            props.add(prop);
            final Collection<? extends String> spVariants = Arrays.stream(PropertyUtils.tokenizePath(loc))
                    .map((p) -> CommonModuleUtils.parseSourcePathVariants(p))
                    .flatMap((lv) -> lv.stream())
                    .collect(Collectors.toList());
            for (File f : file.listFiles()) {
                if (!f.isDirectory()) {
                    continue;
                }
                for (String variant : spVariants) {
                    final String pathInModule = variant;
                    FileObject rfo = FileUtil.toFileObject(file);
                    if (rfo != null) {
                        newmodRoots.add(rfo);
                    }
                    Path fPath = file.toPath();
                    if (rootPath.startsWith(fPath)) {
                        Path rel = fPath.relativize(rootPath);
                        Path intra = Paths.get(pathInModule);
                        String modName = rel.getName(0).toString();
                        if (!pathInModule.isEmpty()) {
                            if (rel.getNameCount() == 1 ||
                                !rel.subpath(1, rel.getNameCount()).equals(intra)) {
                                continue;
                            }
                        }
                        MultiModuleGroupQuery.Result fres = new MultiModuleGroupQuery.Result(modName, pathInModule);
                        synchronized (this) {
                            if (ver == version.get()) {
                                return cachedModuleInfo.computeIfAbsent(grp, (g) -> fres);
                            } else {
                                return fres;
                            }
                        }
                    }
                }
            }
        }
    }
    synchronized (this) {
        if (ver == version.get() && !cachedModuleInfo.containsKey(grp)) {
            cachedModuleInfo.put(grp, NONE);
            watchedProperties.addAll(props);
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:80,代码来源:MultiModuleGroupQueryImpl.java

示例15: getFileFromCache

import java.io.File; //导入方法依赖的package包/类
Path getFileFromCache(String filename) throws IOException {
  File src = FileUtils.toFile(getClass().getResource("/" + filename));
  File destFile = new File(new File(userHome, "" + filename.hashCode()), filename);
  FileUtils.copyFile(src, destFile);
  return destFile.toPath();
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:7,代码来源:DefaultPluginJarExploderTest.java


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