ist das eine hausaufgabe oder ein eigenes/kommerzielles projekt? wenns eine hausaufgabe ist, musst du den pfad parsen (dazu dann mehr) wenn nicht, nimm File (Java Platform SE 6). Da spielt es überhaupt keine Rolle, wieviel backslashes/slashed jeweils im pfad vorkommen (wobei backslashes natürlich maskiert werden müssen).
ist das eine hausaufgabe oder ein eigenes/kommerzielles projekt? wenns eine hausaufgabe ist, musst du den pfad parsen (dazu dann mehr) wenn nicht, nimm File (Java Platform SE 6). Da spielt es überhaupt keine Rolle, wieviel backslashes/slashed jeweils im pfad vorkommen (wobei backslashes natürlich maskiert werden müssen).
Wie definierst du einen gültigen Pfad? Z.B. [c]a//bc/[/c] würde ich als [c]a/bc/[/c] interpretieren. Und wenn du noch [c].[/c] (aktuelles Verzeichnis) und [c]..[/c] (Parent) kennst, dann wär auch [c]a/../././././a/b[/c] gültig?
Wie definierst du einen gültigen Pfad? Z.B. [c]a//bc/[/c] würde ich als [c]a/bc/[/c] interpretieren. Und wenn du noch [c].[/c] (aktuelles Verzeichnis) und [c]..[/c] (Parent) kennst, dann wär auch [c]a/../././././a/b[/c] gültig?
nodeExists
public abstract boolean nodeExists(String pathName)
throws BackingStoreExceptionReturns true if the named preference node exists in the same tree as this node. Relative path names (which do not begin with the slash character ('/')) are interpreted relative to this preference node.
If this node (or an ancestor) has already been removed with the removeNode() method, it is legal to invoke this method, but only with the path name ""; the invocation will return false. Thus, the idiom p.nodeExists("") may be used to test whether p has been removed.
Parameters:
pathName - the path name of the node whose existence is to be checked.
Returns:
true if the specified node exists.
Throws:
BackingStoreException - if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it. IllegalArgumentException - if the path name is invalid (i.e., it contains multiple consecutive slash characters, or ends with a slash character and is more than one character long). NullPointerException - if path name is null. s * @throws IllegalStateException if this node (or an ancestor) has been removed with the removeNode() method and pathName is not the empty string ("").
ok dann ist meine methode dann diese...um zu gucken ob der Pfad gültig ist oder nicht
wenn er gültig ist dann kommt true raus
wenn er ungültig ist false!
Java:
publicbooleanisValidPath(String pathnName){if(pathnName.endsWith("/")){returnfalse;}int index =pathnName.indexOf("//");if(index >-1){returnfalse;}returntrue;}
und die exception muss ich jetzt in diese methode einbauen
Java:
@OverridepublicbooleannodeExists(String pathName)throwsIllegalArgumentException{if(isValidPath(pathName)==true)try{if(pathName.isEmpty()){returnfalse;}int index = pathName.indexOf("/");if(index ==0){// absoluter Pfad// zum relativen pfad machen zur weiter verarbeitung
pathName = pathName.substring(index +1);}SimplePreferences value = nodeMap.get(pathName);if(value !=null)returntrue;
index = pathName.indexOf("/");if(index <0){// Wenn der index < 0 ist wurde kein Slash mehr// gefunden, dann ist es der letzte Knoten
value = nodeMap.get(pathName);// prüfen ob knoten// vorhanden istif(value !=null)returntrue;returnfalse;}String[] split = pathName.split("/");for(int i =0; i < split.length; i++){
value = nodeMap.get(split[i]);// prüfen ob knoten// vorhanden istif(value !=null)returntrue;}returnfalse;}catch(IllegalArgumentException e){// TODO: handle exception
e.getMessage();}returnfalse;}
kann mir da jemand helfen.hatte noch nicht viel mit exception zu tun!:rtfm:
so wie ich es jetzt hab,habe ich es verstanden durchs belesen!:rtfm::rtfm: