samedi 21 février 2015

How to take a string parameter (will be the path name of a file) and perform File methods like exists() and setReadOnly on it?


import java.io.File;


public class Attrib { /* Command:: attrib name where name must be the name of a file and its path. Action: Makes the file read only. */



public Attrib(String name){

boolean bool = false;
bool = name.exists();
if(bool){
bool = name.setReadOnly();
System.out.println("success? " + bool);}

if(name.isDirectory()){
System.out.println("file is a directory");}
}

private void f(String name){
System.out.print(name);
}


} The purpose of this program is make an existing file read only. For some reason, I keep getting the error code when I try to compile "cannot find symbol - method exists()". I guess you cannot perform exists(), or any other File method on a path-name that is represented as a string? Maybe I can convert the string path-name to a file object or something?


Aucun commentaire:

Enregistrer un commentaire