List of usage examples for java.io File canRead
public boolean canRead()
From source file:Main.java
public static void main(String[] args) { String filePath = "C:/Text.txt"; File file = new File(filePath); if (file.canRead()) { System.out.println("readable"); } else {//from www . j a v a 2s . co m System.out.println("not readable"); } }
From source file:MainClass.java
public static void main(String[] a) { File file = new File("c:\\text.txt"); file.setReadOnly();//w w w . j av a2 s .co m System.out.println(file.canRead()); }
From source file:MainClass.java
public static void main(String[] a) { File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java"); System.out.println(myFile.canRead()); }
From source file:Main.java
public static void main(String[] args) { File f = new File("c:/test.txt"); // returns true if the file can be read boolean bool = f.canRead(); System.out.print("File can be read: " + bool); }
From source file:Attr.java
public static void main(String args[]) { File path = new File(args[0]); // grab command-line argument String exists = getYesNo(path.exists()); String canRead = getYesNo(path.canRead()); String canWrite = getYesNo(path.canWrite()); String isFile = getYesNo(path.isFile()); String isHid = getYesNo(path.isHidden()); String isDir = getYesNo(path.isDirectory()); String isAbs = getYesNo(path.isAbsolute()); System.out.println("File attributes for '" + args[0] + "'"); System.out.println("Exists : " + exists); if (path.exists()) { System.out.println("Readable : " + canRead); System.out.println("Writable : " + canWrite); System.out.println("Is directory : " + isDir); System.out.println("Is file : " + isFile); System.out.println("Is hidden : " + isHid); System.out.println("Absolute path : " + isAbs); }/*from w w w. j a v a2s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { File file = new File(args[0]); if (!file.exists()) { System.out.println(args[0] + " does not exist."); return;/* ww w . j a v a 2s . c om*/ } if (file.isFile() && file.canRead()) { System.out.println(file.getName() + " can be read from."); } if (file.isDirectory()) { System.out.println(file.getPath() + " is a directory containing..."); String[] files = file.list(); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); } } }
From source file:Main.java
public static void main(String[] args) { File file = new File(args[0]); if (!file.exists()) { System.out.println(args[0] + " does not exist."); return;/* w w w.j a va2 s . c o m*/ } if (!(file.isFile() && file.canRead())) { System.out.println(file.getName() + " cannot be read from."); return; } try { FileInputStream fis = new FileInputStream(file); char current; while (fis.available() > 0) { current = (char) fis.read(); System.out.print(current); } } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { File f = new File("name.txt"); if (!f.exists()) { System.out.println("File not found."); return;/*from w w w .ja v a 2s . com*/ } if (f.canRead()) System.out.println(" Readable"); else System.out.println(" Not Readable"); if (f.canWrite()) System.out.println(" Writable"); else System.out.println(" Not Writable"); System.out.println(" Last modified on " + new Date(f.lastModified())); long t = Calendar.getInstance().getTimeInMillis(); if (!f.setLastModified(t)) System.out.println("Can't set time."); if (!f.setReadOnly()) System.out.println("Can't set to read-only."); if (f.canRead()) System.out.println(" Readable"); else System.out.println(" Not Readable"); if (f.canWrite()) System.out.println(" Writable"); else System.out.println(" Not Writable"); System.out.println(" Last modified on " + new Date(f.lastModified())); if (!f.setWritable(true, false)) System.out.println("Can't return to read/write."); if (f.canRead()) System.out.println(" Readable"); else System.out.println(" Not Readable"); if (f.canWrite()) System.out.println(" Writable"); else System.out.println(" Not Writable"); }
From source file:hisqisnoten.HisqisNoten.java
public static void main(String[] args) { options = new Options(); options.addOption("h", "help", false, "this help"); options.addOption("u", "user", true, "username for hisqis"); options.addOption("p", "pass", true, "password for hisqis"); options.addOption("c", "console", false, "console mode instead of gui mode"); CommandLineParser parser = new PosixParser(); try {/*from ww w .j a va2 s.c o m*/ CommandLine cmdline = parser.parse(options, args); if (cmdline.hasOption("help")) { printHelp(); System.exit(0); } if (cmdline.getArgList().size() != 0) { System.err.println("Please use the new commandline options."); System.out.println(); printHelp(); System.exit(1); } HisqisSettings settings = null; HisqisSettings.genConfigPath(); for (File configpath : HisqisSettings.configpath) { if (configpath.exists() && configpath.canRead()) { settings = HisqisSettingsReader.loadDocument(configpath); if (settings != null) { break; } } } if (settings == null) { settings = new HisqisSettings(); } String user = cmdline.getOptionValue("user", null); String pass = cmdline.getOptionValue("pass", null); if (user != null) { settings.username = user; } if (pass != null) { settings.password = pass; } if (cmdline.hasOption("console")) { new HisqisConsole(settings); } else { new HisqisGUI(settings); } } catch (ParseException e) { printHelp(); } }
From source file:Main.java
public static void main(String[] args) { File f = new File("C:/test.txt"); // set read permission boolean bool = f.setReadable(true); System.out.println("setReadable() succeeded?: " + bool); // checks whether the file is readable bool = f.canRead(); System.out.print("Is file readable?: " + bool); }