12-19-2011 03:54 AM
hi ,
i am trying to list all the zip files , and zip file parts in a folder .
the contents of the folder are ,
1)one.txt
2)two.zip
3)tree.zip.part
4)four.zip.part
but when i use fc.list()
then it is only taking the text file not the zip file, or the zip parts plss , help me how to list the zip files n zip parts .
Solved! Go to Solution.
12-19-2011 04:33 AM
12-19-2011 04:53 AM
There is no built-in support for zip archives in BlackBerry. If you want to look at the contents of a zip archive, you will have to write code to read it yourself. it is not that hard, the Zip archive format is well documented.
Alternatively, you can look at ZipME, which does this, Having said that, I have had problems extracting file using ZipME, though they were probably my own fault. But it read the Zip archive OK.
12-22-2011 06:59 AM
Hi ,
i will explain in detail .
1) I have a folder Flights
2) In the folder flights there are 2 zip files
a)Flights1.zip
b)Flights2.zip
And there are 41 zip parts
a)Flights.zip.part1
b)Flights.zip.part2
and so on till Flights.zip.part41
when i actually want to read all the files in the folder using command
fileEnum = fileConn.list("*.zip",true);
it is list only the 2 zip files .
So now i have created the parts with names Flights.zip1 , Flights.zip2 ................till Flights.zip41
Still it is reading only 2 zip file s
Flights1.zip and Flights2.zip But not the part files.
So plss help me with an idea or a code snippet as to how to list the files in the folder.
12-22-2011 07:22 AM
12-22-2011 11:59 PM
Thank You maadani , it helped now it is reading the parts . Thank you very much . But when i am adding this data into a vector , it reads the data in a very weird way. it reads
First Flights.zip.part1
then flights.zip.part10, then 11 , so on till part 19
then it reads flights.zip.part2 after that it reads flights.zip.part21 tilll part29
then reads flights.zip.part3 and then from 31 to 39 ,
last parts , 4 ,5 ,6 , 7, 8, 9,
can u tell me how to make them read in or der , or atleast how to sort them properly and add them to the vector
or should i sort the vector.
Plss do not mind me i am new to the whole thing
12-23-2011 06:03 AM
can plss anybody help me how to write a simplesorting vector in this example . i am very confused
i want to use a simplesorting Vector in place of a vector .i need to sort all the names in the vector so that i can read each and every name
so wat i am doing initially i am giving fc.list and adding all the names of the files in a vector fileNames .
BUt i have read that to apply simpleSortingVector we need to apply the comparator in the begining .
i have written a comparator class but that class from which it is getting data for compare is set after the reading of the vector with the vector data itself.
i mean i have to compare the files names which will be in the vector after it is read then that vecctor i am changing to an array and then that data i initializing to the bean class
i know i have hotch pochted the whole code .I am attaching a sippet of the code plsss correct where i am wrong or suggest me something else where i can compare the file names in the vector , sort them in proper order and retrieve them .
public void readDataFrmZip()
{
Enumeration fileEnum;
String _currentFile;
DataOutputStream dout = null;
FileConnection fileConn=null,fConn=null;
FileConnection file = null;
SimpleSortingVector filesVector= new SimpleSortingVector();
filesVector.setSortComparator(new FileNameComparator());
filesVector.setSort(true);
String path = "file:///SDCard/Databases/glide/Flights/" ;
String extensions = "*.zip.part";
try
{
fConn = (FileConnection)Connector.open("file:///SDCard/Dat
fileConn = (FileConnection)Connector.open("file:///SDCard/Dat
if (!fConn.exists())
{
fConn.create(); // create the file if it doesn't exist
}
OutputStream out = fConn.openDataOutputStream();
if (path == null)
{
//Read the file system roots.
fileEnum = FileSystemRegistry.listRoots();
while (fileEnum.hasMoreElements())
{
filesVector.addElement((Object)fileEnum.nextElemen
}
}else{
fileEnum = fileConn.list("*.part*", true); // list of all files in folder flights
while(fileEnum.hasMoreElements())
{
if (extensions == null)
{
filesVector.addElement((Object)fileEnum.nextElemen
}else
{
_currentFile = ((String)fileEnum.nextElement());
filesVector.addElement((Object)_currentFile); //this is where i am adding all the file names to the vector
}
}
}
filesVector.reSort();
int size= filesVector.size();
String temp;
flightsVector = filesVector;
FileName filecomp[] = new FileName[size];
String fileNames[] = new String[size];
filesVector.copyInto(fileNames);
for(int i=0;i<=size;i++)
{
temp = fileNames[i];
filecomp[i] = new FileName();
filecomp[i].setName(temp);
}
for(int i =0;i<=size;i++)
{
System.out.println("***********************"+fileN
}
for(int i=0;i<=size;i++)
{
i++;
System.out.println("/////////////"+fileNames[i]);
String flight = "Flights_20111202.zip.part";
String path1 ="Flights_20111202.zip.part" +i ;
System.out.println("+++++++++++++"+path1);
file = (FileConnection)Connector.open("file:///SDCard/Dat
InputStream in = file.openDataInputStream();
int count=0;
byte [] data =new byte[1048576];//IOUtilities.streamToBytes(in);
while ((count = in.read(data)) != -1)
{
out.write(data,0,count);
System.out.println("########## " + i + " = " + count);
}
in.close();
file.close();
}
out.flush();
out.close();
}catch (IOException e) {
System.out.println("Exc in readDataFrmZip: "+e);
e.printStackTrace();
}finally{
try {
fConn.close();
fileConn.close();
} catch (IOException e) {
// TODO Auto-generated catch blockF
e.printStackTrace();
}
}
}
The above given was the method.
Now the comparator class
public class FileNameComparator implements Comparator {
public int compare(Object o1, Object o2) {
FileName emp1 =new FileName();
FileName emp2= new FileName();
String file1Name = ((FileName)emp1).getName();
String file2Name = ((FileName)emp2).getName();
//uses compareTo method of String class to compare names of the employee
return file1Name.compareTo(file2Name);
// return 0;
}
}
the classfrom which this comparator cass gets the data to compare that class is as follows:
public class FileName {
private String name;
public void setName(String name){
this.name=name;
}
public String getName(){
return this.name;
}
}
plss help me how should i sove my this problem .plssss help meee plsss
12-23-2011 06:53 AM
Hi,
You can use the SimpleSortingVector APi:
http://www.blackberry.com/developers/docs/5.0.0api
Just implement your comparator and add your objects to the vector.
E.
12-24-2011 07:13 AM
Sorry, just realize you are already using the SimpleSortingVector...
You should build your comparator to compare the file names by the part ids and then you can use it when initiating the Vector.
In the vector, just hold the names of the files (Strings).
One last thing, the comparing is done according to dictionary order, so comparing strings won't do the trick.
Extract the substring that contains the part number and compare the integers.
Try this code:
public class FileNameComparator implements Comparator {
public int compare(Object o1, Object o2) {
String file1Name = ((String)o1);
String file2Name = ((String)o2);
int part1 = Integer.parseInt(file1Name.subString(file1Name.las tIndexOf(".part") + ".part".length()));
int part2 = Integer.parseInt(file2Name.subString(file2Name.las tIndexOf(".part") + ".part".length()));
return part1-part2;
}
}
And in your vector, hold only the relevant file names.
Please note that my code was not tested, so you would probably need to add exception handling, test the for the correct index in the string, etc', etc'...
Hope that helps,
E.
01-01-2012 10:50 PM
hi ,
Firstly Wishing all of you a very Happy And prosperous New Year !!!!!!!
Hi Maadani ,
i would like to add a new req actually , i have to read the files not from one folder , i have to read it from the server after making an ftp call ,the actual requirement is
1) Make an FTp call to the server
2) in the server address there is a folder by name Flights
3)In that folder there are many part files of one big file flight.zip for eg , flight.zip.part1, part2 and so on .So all these part files are present in that one folder Flight ,on the server side .
4)Get the total no of files from the foledr on the server .
5)then read each of the zip part file
6)then download and write it to the local disk
7)after we reach the end of the files of the folder in the server , and write them on to the local disk
, 8)Then club all the part files into one big zip file
.the clubbing of all part files to one zip file is complete , but how to dynamically read the no of files on a folder on the server side , plss help me with that plsss ......