java - How can i make string save into a text file only if it starts with !test? -


    try {         scanner majora = new scanner(system.in);         system.out.println("what name?");         string link = majora.nextline();         scanner lenk = new scanner(system.in);         system.out.println("name of file?");         string lunk = lenk.nextline();         if(link.equalsignorecase("!addcom");         file ocarina = new file("/users/unknown/desktop/commands/" + lunk + ".txt");         if (ocarina.exists()) {             ocarina.createnewfile();         }         filewriter majoras = new filewriter(ocarina.getabsolutefile());         bufferedwriter zelda = new bufferedwriter(majoras);         zelda.write(link);         zelda.close(); } 

this got far :/

i need on making if word used before string wanna save. save string.

use startswith string method

if(link.startswith("!test")) zelda.write(link); 

substring string without !test 5 characters

link = link.substring(5); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -