how to ge the variable status?????

gagajanice
gagajanice used Ask the Experts™
on
how to check the file of the image is using or not?
currenly i am doing the application for blackberry.... which is send the image by email...
and image will only save in one folder.... once finish capture the image, it will retrieve all the image from the folder, then send by email, during sending...  the user also continue for the next capture ... once finish it will retrieve from the same folder to send by email, to prevent to ge tthe duplicate image, it will do the verify, weather the image status is using or not, if yes, means the photo already "sending or pending. the retrieve only will get the new image the one i just finish capture.
the image will delete only when the email send successfully.....

i need a solution about how to get the variable status the file is "using" ???
thank you to give me the solution with syntax.. i am newbie in java and this new platform...
thankx..


package com.rim.samples.device.sendmediademo;
 

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import net.rim.blackberry.api.mail.*;
import net.rim.device.api.io.file.ExtendedFileConnection;
import net.rim.device.api.system.*;
 
public class Lesson2Screen extends Application {
 //private Store store;
 //private String test;
 //private Store Collections;
 static void main (String args[]) {
  Lesson2Screen app = new Lesson2Screen();
 app.enterEventDispatcher();
 }
 Lesson2Screen() {
 Store store = Session.getDefaultInstance().getStore();
 
 //create a multipart   
             
    String root="file:///store/home/user/pictures/";
    FileConnection fc1 = null;
    Enumeration rootEnum = null;
    Vector elementData = new Vector();
    Multipart mp = new Multipart();
    if (root != null) 
    {
        // Open the file system and get the list of directories/files
        try 
        {                
         fc1 = (FileConnection)Connector.open(root);
         rootEnum = fc1.list();
         
         //Vector elementData = new Vector();
         while( rootEnum.hasMoreElements() ){
                elementData.addElement(rootEnum.nextElement());
         }
         //int elementCount = elementData.size();
         //String first = (String) elementData.elementAt(0);
    
        }   
        catch (Exception e) 
        {
            return;
        }
        finally 
        {                
            if (fc1 != null) 
            {   
                try 
                {
                    fc1.close();
                    fc1 = null;
                } 
                catch (IOException e) 
                { 
                }
            }
        }

    }     

         int elementCount = elementData.size();
      
         ExtendedFileConnection fc = null;
         InputStream fis = null;
         byte imageData[] = null;
         try{
       
        	 int tempcount = 0;
        	 
        	
        	 
        	 
        	 
    	 for (int i = tempcount; i < elementCount; i++)
         {

    		 String IMAGEARRAY = (String) elementData.elementAt(i);
		 
    	     String filePath = "file:///store/home/user/pictures/" + IMAGEARRAY;
    		   
             fc = (ExtendedFileConnection) Connector.open(filePath, Connector.READ);
         
**********************************
*********************************
*********************************
may be i will add the verify in here, it will check the image status is using, then it will skip to continue for the next loop. if not this part, hopefully u can teach me which part need to add... what kind of the attribute use to check?
thank you to provide me the solution with syntax... thank you
******************************
******************************
******************************


             if(fc.exists()){
             fis = fc.openRawInputStream();
          
           //  int len = (int) fc.rawFileSize();
          
             int len = (int)fc.fileSize();
             //data = new byte[fileSize]; 
             imageData = new byte[len];
          //   int length = fis.read(imageData, 0, len);
  
             SupportedAttachmentPart sap = new
        	SupportedAttachmentPart(mp,"image/jpeg",IMAGEARRAY, imageData);  
             
        	 mp.addBodyPart(sap); 
         }
         }
     }catch(OutOfMemoryError error){
      System.gc();
         //in case of out of memory error replace with dummyImage
         System.out.println("Out of Memory Exception in creating Image: "+error.getMessage());
     }catch(Exception e){
      System.gc();
         System.out.println("Exception in reading file data: "+e.getMessage());
         e.printStackTrace();
     }finally{
      try{
       fc.close();
       System.out.println("FileConnection closed successfully");
      }catch(Exception e){
       System.out.println("Error while closing file Connection"+e.getMessage());
      }
     }


 
 Folder[] folders = store.list(Folder.SENT);
 Folder sentfolder = folders[0];
 // Create message.
 Message msg = new Message(sentfolder);
 // Add TO Recipients.
 Address toList[] = new Address[1];
 try {
 toList[0]= new Address("CEO@google123.com", "Bill Gates");
 } catch(AddressException e) {
 System.out.println(e.toString());
 
 
 }
 try {
 msg.addRecipients(Message.RecipientType.TO, toList);
 } catch (MessagingException e) {
 System.out.println(e.toString());
 }
 // Add CC Recipients.
 Address ccList[] = new Address[1];
 try {
 ccList[0]= new Address("COO@google1234.com", "Bill Gates Wife");
 } catch(AddressException e) {
 System.out.println(e.toString());
 }
 try {
 msg.addRecipients(Message.RecipientType.CC, ccList);
 } catch (MessagingException e) {
 System.out.println(e.toString());
 }
 // Add the subject.
 msg.setSubject("Google Image");
 // Add the message body.
 try {
 msg.setContent(mp);
 } catch(MessagingException e) {
 // Handle messaging exceptions.
 }
 // Send the message.
 try {
 Transport.send(msg);
 } catch(MessagingException e) {
 System.out.println(e.getMessage());
 }
 System.out.println("Email sent successfully.");
 
 //FileConnection fconn;
try {

	 for (int j = 0; j < elementCount; j++)
     {
		 
    String IMAGEARRAY = (String) elementData.elementAt(j);
	String filePathCLOSE = "file:///store/home/user/pictures/" + IMAGEARRAY;
	FileConnection fconn = (FileConnection)Connector.open(filePathCLOSE);
		
	if(fconn.exists()){
	fconn.delete();
	fconn.close();
     }}
} catch (IOException e) {
	 e.printStackTrace();
     e.getMessage(); //tell me what this says

}

 System.exit(0);
 }
 
//...when this screen closes, onClose() will be run
    public boolean onClose() {
        //force the app to quit
        System.exit(0);
        return true;
    }  

}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
can provide me the solution with syntax?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Author

Commented:
i try, it doesn;t work in blackberry patform...it have a lot of red color error line...

Author

Commented:
beisde lockfile.. got any other method? is it possible to check the attribute?

Author

Commented:
still cannot... many red color error line...
any other method?
where are you getting the red error line? on which api?
Hi, everyone... i am doing the blackberry application.. it is not support for lockfile and canWrite and canRead in blackberry platform.. finally i wil using the update name to check instead of file status...
hihihi
thank you all

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial