×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    27

    Can i do this without having to permit file reading every time?

    I want to search after words in a file, i have created a search class which extends Thread, but everytime i serach i have to create a new object and have to permit the app to access the file. Is there a way to implement this so that don't have to do this every time?

    I have tried several things but still haven't been successfull,

    thanks in advance!

    PHP Code:
    class ReadThread extends Thread {
             
    String fileName null;
         
    String currDirName null;
         
    StringItem status null;
         
    String word "";
         
    FileConnection fconn null;
         
    InputStream is null;
         
             
    ReadThread(String fileNameString currDirNameStringItem status) {
             
    this.fileName fileName;
             
    this.currDirName currDirName;
             
    this.status status;
             
            
             }
         
         
    void setWord(String word){
             
    this.word word;
         }
     
             public 
    void run() {
             
            try {
                 
    fconn = (FileConnection)Connector.open("file://localhost/" currDirName fileNameConnector.READ);
                 
    is fconn.openInputStream();
            } catch (
    Exception ex) {ex.toString();}
             
             
            
    long timer System.currentTimeMillis();
            
            
    int buffer_size=20000;
            
    byte[] = new byte[buffer_size];
            
    int index_start 0;
            
    int index_stop 0;
            
    int length 0;
            
    String buffer_string ="";
            
    char n '\n';
            
    boolean found false;
            
            
            
            while(
    true){
                
                try{
                    
    length is.read(b0buffer_size);
                } catch (
    Exception ex) {ex.toString();}
                
                if(
    length == -1//slutet på filen, hittar inget!
                    
    break;
                
                
    buffer_string buffer_string + new String(b);
                
                while(
    true){
                 
                 
    index_start buffer_string.indexOf("\n"+word);
                 if(
    index_start == -1){  //hittar inte
                     
                     
    index_start buffer_string.lastIndexOf(n);
                     
    buffer_string buffer_string.substring(index_start); 
                     
                    
    // try{
                    //     this.sleep(100);
                      //} catch (Exception ex) {ex.toString();}
                     
    break;
                     
                 }
                 else{
                     
    index_start++; //pga \n i sökningen
                     
    int bajs 99;
                     if ( 
    is.markSupported() )
                         
    bajs 98;
                     
    status.setText(System.currentTimeMillis()-timer +" ms to find " " "+index_start+buffer_string.substring(index_startindex_start+word.length() )  + bajs);
                     
    found true;
                     break;
                     
                 }
                 
                }
                
                if(
    found == true)
                    return;
                    
            }
            
            try{
                
    System.out.println("close");
                
    is.close();//släpper filen
            
    } catch (IOException e) {}
            
         }
                 


  2. #2
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    387

    Re: Can i do this without having to permit file reading every time?

    hi, i guess you are having problem due to pop up given by kvm......app want to access user data, is it ok? some thing like that? than only signing could help it.
    Thanks and Regards,
    Manjul.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    27

    Re: Can i do this without having to permit file reading every time?

    Quote Originally Posted by manjul_saini View Post
    hi, i guess you are having problem due to pop up given by kvm......app want to access user data, is it ok? some thing like that? than only signing could help it.
    yes that is it,

    but i was thinking, this part is the part where the question is asked:

    try {
    fconn = (FileConnection)Connector.open("file://localhost/" + currDirName + fileName, Connector.READ);
    is = fconn.openInputStream();
    } catch (Exception ex) {ex.toString();}


    is it possible to implement so that this only is made once? and then the search in the file using the InputStream multiple times,

    i have tried with the above code in a separate thread passing the InputStream to another thread where i do the serching but the app freezes.

    all help will make me happy :-)

    thanks in advance

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: Can i do this without having to permit file reading every time?

    Make a DataInputStream of IS everytime you want to resuse your IS.

    public DataInputStream(InputStream in)
    Creates a DataInputStream and saves its argument, the input stream in, for later use.


    Or try Mark() and Reset() on your IS if it is supported.

    thanks,
    ~Amitabh
    Last edited by im2amit; 2009-08-21 at 18:46.

  5. #5
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    387

    Re: Can i do this without having to permit file reading every time?

    Hi signing of app can only help you. in this case it will ask you only once.
    Thanks and Regards,
    Manjul.

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: Can i do this without having to permit file reading every time?

    Sign your application with a Trusted certificate and set the permission for reading user data as "Ask only Once" and it will help you.

    thanks,
    ~Amitabh
    Visit My Website

  7. #7
    Nokia Developer Champion
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: Can i do this without having to permit file reading every time?

    Quote Originally Posted by Bertil_ View Post
    yes that is it,

    but i was thinking, this part is the part where the question is asked:

    try {
    fconn = (FileConnection)Connector.open("file://localhost/" + currDirName + fileName, Connector.READ);
    is = fconn.openInputStream();
    } catch (Exception ex) {ex.toString();}


    is it possible to implement so that this only is made once? and then the search in the file using the InputStream multiple times,

    i have tried with the above code in a separate thread passing the InputStream to another thread where i do the serching but the app freezes.

    all help will make me happy :-)

    thanks in advance
    what do u mean by the bold lines? What i got from ur statement is u wanna create Connection once then wanna use inputstream multi times? yes u can do this. But once u have read the data from inputstream then u cant read the same data again. for that u have to open the inputstream again if wanna the same data again. If data is quite not bigger in size then u can hold the data in buffer.
    thanks,
    jitu_goldie..

    KEEP TRYING..

Similar Threads

  1. [moved] Theme Studio Error
    By TalJ in forum Themes/Carbide.ui
    Replies: 2
    Last Post: 2009-09-06, 03:39
  2. [split] mbm build error
    By mando222 in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2009-03-29, 12:32
  3. Reading file takes more time on Nokia E61i while less time on Nokia 2626
    By arpit2agrawal in forum Mobile Java General
    Replies: 5
    Last Post: 2008-10-15, 14:57
  4. Replies: 13
    Last Post: 2007-12-07, 11:21
  5. Problem in Reading a file using RFileReadStream
    By ash_21 in forum Symbian C++
    Replies: 15
    Last Post: 2007-10-24, 13:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •