Generating a Batch File - Static Method Error
Hey guys, I'm clearly new here, scoured the internet for a solution to my problem but could not find one, so I figured I'd make a post on the first forum I found, which is this one! (congratulations).
Anyways:
Code :
import java.io.*;
public class UpdateACL {
private FileOutputStream fos;
private DataOutputStream dos;
private static String projectName = "";
private static String projectPath = "xcopy C:\\st22615_SharedTools_mainline_intg\\vobs\\sharedtools\\src\\ClearCase\\triggers\\acl\\project\\" +
projectName + "\\* \\0\\cm\\acl\\project\\" + projectName + "/y /r /s /i" + "pause";
public void ChangeACL() throws FileNotFoundException, IOException {
File file;
file = new File("C:\\samplenote.bat");
fos=new FileOutputStream(file);
dos=new DataOutputStream(fos);
dos.writeBytes(projectPath);
}
public static void main(String args[]){
try{
System.out.print("Enter the project name:");
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
projectName = in.readLine();
ChangeACL(); //Calling this method gives non-static method call in static context error
} catch (FileNotFoundException e) {
System.err.println("FileNotFoundException: " + e.getMessage());
} catch (IOException e) {
System.err.println("Caught IOException: " + e.getMessage());
}
}
}
I'm basically trying to generate a batch file that will hold that string, that I can run immediately after it is generated...however I cannot call Change.ACL(), even though it is in the same class? Confusing...
If anyone could provide insight on this that would be great.
Cheers.
Re: Generating a Batch File - Static Method Error
Quote:
I cannot call Change.ACL()
Please post the full text of the compiler's error message.
Re: Generating a Batch File - Static Method Error
Change the code to be either:
Code :
public static void ChangeACL() throws FileNotFoundException, IOException {
(notice the static declaration) or
Code :
UpdateACL updateACL = new UpdateACL();
updateACL.ChangeACL();
in your main() method.
Re: Generating a Batch File - Static Method Error
Awesome, thanks stdunbar! It all makes sense...