Java space at start of text file -


i have program ask user application want open, how program works:

  • the user write application want open in "inputdialog" example user write "open application notepad".
  • the program looks word "application" in text file program sure application user wanted open.
  • both "open application" sentence , application name stored in text file.
  • then program remove "open application" text file, , application name visible.
  • but space comes in front of application name. please me remove space infront of application name!!

here code:

package test_code; import java.io.bufferedreader; import java.io.bufferedwriter; import java.io.datainputstream; import java.io.fileinputstream; import java.io.filereader; import java.io.filewriter; import java.io.ioexception; import java.io.inputstreamreader; import javax.script.scriptengine; import javax.script.scriptenginemanager; import javax.script.scriptexception; import javax.swing.joptionpane;  public class new_loader_3 {     public static void main(string[]args) throws ioexception{         string test = joptionpane.showinputdialog("test");         bufferedwriter writer = new bufferedwriter(new filewriter("/applications/userdata/tmp/application.txt"));          writer.write(test);          writer.close();           int tokencount;            filereader fr=new filereader("/applications/userdata/tmp/application.txt");            bufferedreader br=new bufferedreader(fr);            string s1;            int linecount=0;            string line;            string words[]=new string[500];                                         while ((s1=br.readline())!=null)                                                 {                                                 linecount++;                                                 int indexfound=s1.indexof("application");                                                                              if (indexfound>-1)                                                                              {                                                                                 fileinputstream fstream1121221 = new fileinputstream("/applications/userdata/tmp/application.txt");                                                                                   datainputstream in1121211 = new datainputstream(fstream1121221);                                                                                   bufferedreader br1112211 = new bufferedreader(new inputstreamreader(in1121211));                                                                                   string name12122131;                                                                                   while ((name12122131 = br1112211.readline()) != null)   {                                                                                     if (name12122131.startswith(" "))                                                                                        {                                                                                           system.out.println("name12122131");                                                                                     }                                                                                   }         string mega = test.replaceall("open application","");          system.out.println(mega);         bufferedwriter update_catch = new bufferedwriter(new filewriter("/applications/userdata/tmp/application.txt"));          update_catch.write(mega);          update_catch.close();                                                                              }                                                 }         system.out.println("done");     } } 

it's because user types in open<space>application<space>notepad. when replace open<space>applicaton space before notepad still left. use instead:

string mega = test.replaceall("open application ",""); 

adding <space> @ end of open<space>application replace space too. mega notepad.

otherwise use you're using , call mega.trim()


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -