當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。