Why isn't J2ME able to create recursive direct

2019-03-04 09:38发布

问题:

I want to create recursive directories ( for example : Connector.open("file:///Phone:/folder_1/folder_2/", Connector.READ_WRITE); ). The problem is that the two folders , here folder_1 and folder_2, are not mentioned explicitly but instead there is only one String parameter provided from a method. For example :

private void myMethod(String path) 
{
  fcDir = (FileConnection) Connector.open("file:///Phone:/"+path+"/", Connector.READ_WRITE);
...
}

And in runtime the two folders are not created ! So I must create separately two FileConnection in order to create the two folders ! So why J2ME is not able to make a recursive directory creation ?

回答1:

you may also try thing new way. you can make your method recursive, now pass one vector & integer parameter, vector's element will be the list of directories you want to create and integer will specify the number of time method should call it self.

i.e. for folder_1 & folder_2 you can pass parameter as method_name ( folderVector, 2 ). here folderVector variable contains two String element as folder_1 & folder_2. Now you need to call your method recursively such that , each time second parameter decrements it's value with one down. Run this method till it is greater than zero.

This is the one way you can do it recursively.