Hi,
Ich brauche bitte mal hilfe bei folgendem Code:
In Zeile 48, wo jetzt "TRYTOHACKTHIS" steht will ich einen beliebigen Wert der gerade an der Stelle in der SQL Datei steht löschen.
Wie kann ich das machen, bzw. mir wäre auch recht wenn alles nach dem "Username +" gelöscht werden würde...
danke im voraus :rtfm:
Ich brauche bitte mal hilfe bei folgendem Code:
Java:
package Userverwaltung;
/**
*
* @author
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.File;
import java.io.FileWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class UserLoeschen3 {
private Pattern pattern;
private Matcher matcher;
private static final String USERNAME_PATTERN = "^[A-Za-z0-9_-]{3,225}$";
// static CharSequence username = "TRYTOHACKTHIS";
public UserLoeschen3() {
pattern = Pattern.compile(USERNAME_PATTERN);
}
/**
* Validate username with regular expression
* @param username username for validation
* @return true valid username, false invalid username
*/
public boolean validate(final String username) {
matcher = pattern.matcher(username);
return matcher.matches();
}
public static void UserLoeschen3() {
String Username = GUI.imputUserName.getText();
// String password = USERNAME_PATTERN;
UserLoeschen3 del = new UserLoeschen3();
del.removeLineFromFile("test.sql", "DROP USER " + Username + " CASCADE;");
del.removeLineFromFile("test.sql", "CREATE USER " + Username + " IDENTIFIED BY " + "TRYTOHACKTHIS" + " DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TMP2 PROFILE DEFAULT ACCOUNT UNLOCK QUOTA UNLIMITED ON \"USERS\";");
del.removeLineFromFile("test.sql", "GRANT \"UR_ERFASSER\" TO " + Username + ";");
del.removeLineFromFile("test.sql", "ALTER USER " + Username + " DEFAULT ROLE \"UR_ERFASSER\";");
}
public void removeLineFromFile(String file, String lineToRemove) {
try {
File inFile = new File(file);
if (!inFile.isFile()) {
System.out.println("Parameter is not an existing file");
return;
}
//Construct the new file that will later be renamed to the original filename.
File tempFile = new File(inFile.getAbsolutePath() + ".tmp");
BufferedReader br = new BufferedReader(new FileReader(file));
PrintWriter pw = new PrintWriter(new FileWriter(tempFile));
String line = null;
//Read from the original file and write to the new
//unless content matches data to be removed.
while ((line = br.readLine()) != null) {
if (!line.trim().equals(lineToRemove)) {
pw.println(line);
pw.flush();
}
}
pw.close();
br.close();
//Delete the original file
if (!inFile.delete()) {
System.out.println("Could not delete file");
return;
}
//Rename the new file to the filename the original file had.
if (!tempFile.renameTo(inFile)) {
System.out.println("Could not rename file");
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
UserLoeschen3();
}
}
In Zeile 48, wo jetzt "TRYTOHACKTHIS" steht will ich einen beliebigen Wert der gerade an der Stelle in der SQL Datei steht löschen.
Wie kann ich das machen, bzw. mir wäre auch recht wenn alles nach dem "Username +" gelöscht werden würde...
danke im voraus :rtfm: