本文整理匯總了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"));
}
示例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.");
}
}
示例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;
}
示例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;
}
示例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]);
}
示例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));
}
}
示例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;
}
}
示例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");
}
}
示例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;
}
示例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";
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例15: isFileOk
import java.nio.file.Files; //導入方法依賴的package包/類
private static boolean isFileOk(Path path) {
return Files.isRegularFile(path) && Files.isReadable(path);
}