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


Java Files.isReadable方法代码示例

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


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

示例1: findTFile

import java.nio.file.Files; //导入方法依赖的package包/类
public static Path findTFile(String name, boolean thrw)throws IOException{
    Path p=Paths.get(cpath+"/"+name+".tin");
    if(Files.exists(p) && Files.isReadable(p))
        return p;
    else if(!Files.exists(p)){
        for(String resp:resps){
            p=Paths.get(resp+"/"+name+".tin");
            if(Files.exists(p)){
                if(Files.isReadable(p))
                    return p;
                else
                    throw new IOException(Lingue.getIstance().format("m_nofile", name, "tin"));
            }
        }
        if(thrw)
            throw new IOException(Lingue.getIstance().format("m_nofile", name, "tin"));
        else
            return null;
    }
    else
        throw new IOException(Lingue.getIstance().format("m_nofile", name, "tin"));
}
 
开发者ID:Loara,项目名称:Meucci,代码行数:23,代码来源:FileManager.java

示例2: execute

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * execute.
 * @param cmd - cmd
 * @throws IOException - IOException
 */
@Override
public void execute(Command cmd) throws IOException {
    Path filePath = Paths.get(cmd.getParam());
    if (Files.exists(filePath, LinkOption.NOFOLLOW_LINKS)
            && !Files.isDirectory(filePath) && Files.isReadable(filePath)) {

        System.out.println("Uploading...");

        ObjectOutputStream oos = new ObjectOutputStream(outputStream);
        oos.writeObject(cmd);
        oos.flush();

        WritableByteChannel rbc = Channels.newChannel(new DataOutputStream(outputStream));
        FileInputStream fis = new FileInputStream(cmd.getParam());
        fis.getChannel().transferTo(0, Long.MAX_VALUE, rbc);
        rbc.close();

        System.out.println("Done.");
    } else {
        System.out.println("Error. Please try again.");
    }
}
 
开发者ID:istolbov,项目名称:i_stolbov,代码行数:28,代码来源:CommandFactoryClient.java

示例3: readConfig

import java.nio.file.Files; //导入方法依赖的package包/类
boolean readConfig() throws IOException {
    // we assume we only get called in the root directory of a project
    if (!Files.exists(EADL_CONFIG)) {
        printNotInitialized();
        return false;
    } else if (!Files.isReadable(EADL_CONFIG)) {
        CLI.println("Could not read config file, please check permissions.");
        return false;
    }
    ObjectMapper mapper = new ObjectMapper();
    try {
        this.config = mapper.readValue(EADL_CONFIG.toFile(), Config.class);
    } catch (IOException e) {
        LOG.error("Error reading eadl config file.", e);
        throw e;
    }
    return true;
}
 
开发者ID:adr,项目名称:eadlsync,代码行数:19,代码来源:EADLSyncCommand.java

示例4: scanFile

import java.nio.file.Files; //导入方法依赖的package包/类
private LocalFile scanFile(Path path, boolean useCache) {
    LocalFile file = null;
    if (Files.isReadable(path)) {
        if (useCache && fileCache.containsKey(path)) {
            file = fileCache.get(path);
        } else {
            LocalFileScannerContext context = new LocalFileScannerContext(computationManager);
            for (LocalFileScanner fileScanner : fileScanners) {
                file = fileScanner.scanFile(path, context);
                if (file != null) {
                    break;
                }
            }
            fileCache.put(path, file);
        }
    }
    return file;
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:19,代码来源:LocalAppStorage.java

示例5: listResources

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Method to obtain the paths to all files in a directory specified
 * by a path. This should work in an ordinary file system
 * as well as a (possibly nested) JAR file.
 * 
 * @param path path to a directory (may be contained in a JAR file) 
 * @return a sequence of paths or {@code null} if the specified path 
 * is not a directory
 */
public static Path[] listResources(Path path) {
	// with help from http://stackoverflow.com/questions/1429172/how-do-i-list-the-files-inside-a-jar-file, #10
	if (!Files.isDirectory(path)) {
		throw new IllegalArgumentException("path is not a directory: " + path.toString());
	}
	
	List<Path> pathList = new ArrayList<Path>();
	Stream<Path> walk = null;
	try {
		walk = Files.walk(path, 1);
	} catch (IOException e) {
		e.printStackTrace();
	}

	for (Iterator<Path> it = walk.iterator(); it.hasNext();){
		Path p = it.next();
		if (Files.isRegularFile(p) && Files.isReadable(p)) {
			pathList.add(p);
		}
	}
	walk.close();
	return pathList.toArray(new Path[0]);
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:33,代码来源:ResourceUtils.java

示例6: checkWritePath

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Check if the provided path is a directory and is readable/writable/executable
 *
 * If the path doesn't exist, attempt to create a directory
 *
 * @param path the path to check
 * @throws IOException if the directory cannot be created or is not accessible
 */
public static void checkWritePath(String path) throws IOException {
  java.nio.file.Path npath = new File(path).toPath();

  // Attempt to create the directory if it doesn't exist
  if (Files.notExists(npath, LinkOption.NOFOLLOW_LINKS)) {
    Files.createDirectories(npath);
    return;
  }

  if (!Files.isDirectory(npath)) {
    throw new IOException(format("path %s is not a directory.", npath));
  }

  if (!Files.isReadable(npath)) {
    throw new IOException(format("path %s is not readable.", npath));
  }

  if (!Files.isWritable(npath)) {
    throw new IOException(format("path %s is not writable.", npath));
  }

  if (!Files.isExecutable(npath)) {
    throw new IOException(format("path %s is not executable.", npath));
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:34,代码来源:PathUtils.java

示例7: createPathFromText

import java.nio.file.Files; //导入方法依赖的package包/类
private static Path createPathFromText(String text) {
	if (text == null || text.isEmpty()) return null;
	if (text.startsWith("\"") && text.endsWith("\"")) text = text.substring(1, text.length() - 1);
	if (!text.endsWith(DLL_NAME)) return null;

	try {
		Path path = Paths.get(text);
		if (!Files.isRegularFile(path)) {
			error("Read error", "The DLL file you selected cannot be found.");
			return null;
		} else if (!Files.isReadable(path) || !Files.isWritable(path)) {
			error("Read error", "The DLL file you selected cannot be read from or written to.\n\n" +
					"Make sure that the file is not marked read-only and\n" +
					"that you have the required permissions to write to it.");
			return null;
		}

		return path;
	} catch (InvalidPathException ipe) {
		return null;
	}
}
 
开发者ID:zeobviouslyfakeacc,项目名称:ModLoaderInstaller,代码行数:23,代码来源:MainPanel.java

示例8: matchPath

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public boolean matchPath(Path path) {
	if (Files.isDirectory(path)) {
		return Files.isReadable(path.resolve("plugin.groovy"));
	} else {
		return path.getFileName().toString().endsWith(".groovy");
	}
}
 
开发者ID:DeskChan,项目名称:DeskChan,代码行数:9,代码来源:Main.java

示例9: performListing

import java.nio.file.Files; //导入方法依赖的package包/类
private Set<File> performListing(final File directory, final FileFilter filter, final boolean recurseSubdirectories) {
    Path p = directory.toPath();
    if (!Files.isWritable(p) || !Files.isReadable(p)) {
        throw new IllegalStateException("Directory '" + directory + "' does not have sufficient permissions (i.e., not writable and readable)");
    }
    final Set<File> queue = new HashSet<File>();
    if (!directory.exists()) {
        return queue;
    }

    final File[] children = directory.listFiles();
    if (children == null) {
        return queue;
    }

    for (final File child : children) {
        if (child.isDirectory()) {
            if (recurseSubdirectories) {
                queue.addAll(performListing(child, filter, recurseSubdirectories));
            }
        } else if (filter.accept(child)) {
            queue.add(child);
        }
    }

    return queue;
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:28,代码来源:GetFileFromAttribute.java

示例10: getVScmdPath

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * 
 * @return the String that should lead to a vsDevCMD which is required to
 *         run cbmc on windows
 * @throws IOException in case the VScmd couldn't be found this gets thrown
 */
public static String getVScmdPath() throws IOException {

    File file = new File(SuperFolderFinder.getSuperFolder() + RELATIVEPATHTOVSCMD);

    if (Files.isExecutable(file.toPath())) {
        return file.getPath();
    } else { // we were unable to locate the command promp in the resources
        // and search now for it in the common install directories

        Path x86 = new File("C:/Program Files (x86)").toPath();
        Path x64 = new File("C:/Program Files").toPath();
        String searchTerm = "Microsoft Visual Studio";
        String pathToBatch = "/Common7/Tools/VsDevCmd.bat";

        ArrayList<String> toSearch = new ArrayList<>();
        Files.list(x86).filter(Files::isReadable).filter(path -> path.toString().contains(searchTerm))
                .forEach(VSPath -> toSearch.add(VSPath.toString()));
        Files.list(x64).filter(Files::isReadable).filter(path -> path.toString().contains(searchTerm))
                .forEach(VSPath -> toSearch.add(VSPath.toString()));

        for (Iterator<String> iterator = toSearch.iterator(); iterator.hasNext();) {
            String toCheck = ((String) iterator.next()) + pathToBatch;

            if (Files.isReadable(new File(toCheck).toPath())) {
                return toCheck;
            }
        }

        ErrorForUserDisplayer.displayError("The progam was unable to find a Developer Command Prompt for Visual Studio. \n"
                + " Please install it if you haven't and search for the vsCMD.bat in it! \n"
                + " Please copy the .bat to the folder /windows/ in your BEST install directory"
                + "(named \"VsDevCmd.bat\") so it can be found automatically.");

        return "The progam was unable to find a Developer Command Prompt for Visual Studio. Look at the error log";
    }
}
 
开发者ID:Skypr,项目名称:BEAST,代码行数:43,代码来源:WindowsOStoolbox.java

示例11: visitFile

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
    if (Files.isReadable(file) && isMatch(file)) {
        addFile(file);
    }
    return FileVisitResult.CONTINUE;
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:8,代码来源:FindFileTask.java

示例12: ioResourceToByteBuffer

import java.nio.file.Files; //导入方法依赖的package包/类
public static ByteBuffer ioResourceToByteBuffer(String resource, int bufferSize) throws IOException {
    ByteBuffer buffer;

    Path path = Paths.get(resource);
    if (Files.isReadable(path)) {
        try (SeekableByteChannel fc = Files.newByteChannel(path)) {
            buffer = BufferUtils.createByteBuffer((int) fc.size() + 1);
            while (fc.read(buffer) != -1) ;
        }
    } else {
        try (
                InputStream source = Util.class.getResourceAsStream(resource);
                ReadableByteChannel rbc = Channels.newChannel(source)) {
            buffer = createByteBuffer(bufferSize);

            while (true) {
                int bytes = rbc.read(buffer);
                if (bytes == -1) {
                    break;
                }
                if (buffer.remaining() == 0) {
                    buffer = resizeBuffer(buffer, buffer.capacity() * 2);
                }
            }
        }
    }

    buffer.flip();
    return buffer;
}
 
开发者ID:adamegyed,项目名称:endless-hiker,代码行数:31,代码来源:Util.java

示例13: actionPerformed

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Open file");
    if (fc.showOpenDialog(observer) != JFileChooser.APPROVE_OPTION) {
        return;
    }
    Path file = fc.getSelectedFile().toPath();
    if (!Files.isReadable(file)) {
        JOptionPane.showMessageDialog(observer,
                lp.getString("readingError"), lp.getString("errorTitle"),
                JOptionPane.ERROR_MESSAGE);
        return;
    }

    JNotepadPPDocument openedDocument;
    try {
        openedDocument = new JNotepadPPDocument(observer, file);
    } catch (IOException e1) {
        observer.errorMessage(e1);
        return;
    }
    int index = observer.getEditors().indexOf(openedDocument);
    if (index > -1) {
        observer.getTabs().setSelectedIndex(index);
        return;
    }
    observer.addNewTab(openedDocument);
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:33,代码来源:OpenDocumentAction.java

示例14: ioResourceToByteBuffer

import java.nio.file.Files; //导入方法依赖的package包/类
public static ByteBuffer ioResourceToByteBuffer(String resource, int bufferSize) throws IOException {
    ByteBuffer buffer;

    Path path = Paths.get(resource);
    if (Files.isReadable(path)) {
        try (SeekableByteChannel fc = Files.newByteChannel(path)) {
            buffer = BufferUtils.createByteBuffer((int) fc.size() + 1);
            while (fc.read(buffer) != -1) ;
        }
    } else {
        try (InputStream source = Utils.class.getResourceAsStream(resource);
             ReadableByteChannel rbc = Channels.newChannel(source)) {
            buffer = createByteBuffer(bufferSize);

            while (true) {
                int bytes = rbc.read(buffer);
                if (bytes == -1) {
                    break;
                }
                if (buffer.remaining() == 0) {
                    buffer = resizeBuffer(buffer, buffer.capacity() * 2);
                }
            }
        }
    }

    buffer.flip();
    return buffer;
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:30,代码来源:Utils.java

示例15: isFileOk

import java.nio.file.Files; //导入方法依赖的package包/类
private static boolean isFileOk(Path path) {
    return Files.isRegularFile(path) && Files.isReadable(path);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:4,代码来源:CustomLauncherTest.java


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