Saving files as type in a zip file
This is probably more simple than I think it is, but I'm having trouble reading files back correctly (outside the program) after I've programmatically made the zip file.
I'm trying to zip up selected contents of a database by getting the item, and then writing the contents of the database entry out to the zip file through a byte stream. This all works fine, but all the entries in the zip file are "files" with no extension, so they don't open properly, if at all. Is there a way to save file types correctly in a zip file based on content? The database doesn't preserve filenames, all items are referred to by unique ID's. Any help is much appreciated.
cotton.m wrote:
nsop07 wrote:
cotton.m wrote:
nsop07 wrote:
This is probably more simple than I think it is, but I'm having trouble reading files back correctly (outside the program) after I've programmatically made the zip file.
I'm trying to zip up selected contents of a database by getting the item, and then writing the contents of the database entry out to the zip file through a byte stream. This all works fine, but all the entries in the zip file are "files" with no extension, so they don't open properly, if at all. Is there a way to save file types correctly in a zip file based on content? The database doesn't preserve filenames, all items are referred to by unique ID's. Any help is much appreciated.The bottom line is that your question has nothing to do with zipping at all. You have files and they aren't saved with an extension. I would suggest you get that changed so that when you pull the data from the BLOB filed you can give it a unique name and sensible extension.
That will solve your problem.
The zipping is an extra step but totally irrelevent here.Thanks for the response.
I understand what you're saying, but I can't change the way the information is being stored or pulled from the database, I'm going to be honest with you here this is a big mistake. Fixing what meta data is available about the file in the database is the proper solution here. The person who originally made the database design made a serious error in not accounting for this information.
There is no simple way to do this. You'll have to actually look at the content of the file and determine as best you can what type of file it is. There are some third party libraries that do this sort of thing like http://sourceforge.net/projects/jmimemagic/
But depending on how many types of data this could get ugly in a hurryThat is the OPEN question here though ... how many type of data. If more than say, one, you're so right. But if it's all the same stuff, than there sould be no pblm.
Similar Messages
-
How to get the entries in a jar/zip file contained within a jar/zip file?
If I want to list the jar/zip entries in a jar/zip file contained within a jar/zip file how can I do that?
In order to get to the entry enumeration I need a Zip/JarFile:
ZipFile zip = new ZipFile("C:/java_dev/Java_dl/java_jdk_commander_v36d.zip");
// Process the zip file. Close it when the block is exited.
try {
// Loop through the zip entries and print the name of each one.
for (Enumeration list =zip.entries(); list.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) list.nextElement();
System.out.println(entry.getName());
finally {
zip.close();
Zip file "java_jdk_commander_v36d.zip" contains two zip entries:
1) UsersGuide.zip
2) JDKcommander.exe
How to list the entries in "jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip!/UsersGuide.zip"?
The following code:
URL url = new URL("jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip!/UsersGuide.zip");
JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
zipFile = (ZipFile)jarConnection.getJarFile();
would point to "jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip", which is no help at all and Class JarURLConnection does not have an enumeration method.
How can I do this?
Thanks.
AndreI'm not sure I understand the problem. The difference between a zip and jar file is the manifest file; JarFile is extended from ZipFile and is able to read the manifest, other than that they are the same. Your code
for (Enumeration list =zip.entries(); list.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) list.nextElement();
System.out.println(entry.getName());
}is close to what I've use for a jar, below. Why not use the same approach? I don't understand what you're trying to do by using JarURLConnection - it's usually used to read the jar contents.
String jarName = "";
JarFile jar = null;
try
jar = new JarFile(jarName);
catch (IOException ex)
System.out.println("Unable to open jarfile" + jarName);
ex.printStackTrace();
for ( Enumeration en = jar.entries() ; en.hasMoreElements() ;)
System.out.println(en.nextElement());
} -
Can't print a PDF file that is within a ZIP file.
Can’t print a PDF file that is within a ZIP file. Get message “Windows cannot complete the transaction. The destination file could not be created.” If I save the file and extract the pdf it works. I didn't have to go through this hastle before. If I retry many times it will often work.
ZIP files can be handled in many different ways. If you have a program like WinZip or 7-Zip installed, they will handle it.
If not, Windows will handle it. The message you quote indicates that your situation is handled by Windows, which seems to have a problem with it. Could be caused by recent Windows updates.
Definitely not an Adobe Reader problem. -
How to set "Files of type" when using a "File Browse" item.
Apex 4.0.2
Internet Explorer 7 +
I have a "File Browse" item on a page and need to limit the types of files display to just "text (.txt)" files. How can this be done? Currently, the "Files of type" list shows "All File (*.*)", "Pictures (*.gif,*.png)", and HTML (*.htm,*.html)". In the best case, I would like to not have the "Files of type" list and have the user just limited to text files. However, adding Text files (*.txt)" to the "Files of type" list is ok.
thanks,
WilliamThought i'd do a bit of research after seeing Scotts wonderful ideas.
So it turns out, IE made the file item read only from version 8, for security reasons. Read more: http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
File Upload Control
Historically, the HTML File Upload Control (<input type=file>) has been the source of a significant number of information disclosure vulnerabilities. To resolve these issues, two changes were made to the behavior of the control.
To block attacks that rely on “stealing” keystrokes to surreptitiously trick the user into typing a local file path into the control, the File Path edit box is now read-only. The user must explicitly select a file for upload using the File Browse dialog.
Additionally, the “Include local directory path when uploading files” URLAction has been set to "Disable" for the Internet Zone. This change prevents leakage of potentially sensitive local file-system information to the Internet. For instance, rather than submitting the full path C:\users\ericlaw\documents\secret\image.png, Internet Explorer 8 will now submit only the filename image.png.To resetting the actual items, suggestions I found were to replace the actual item. So instead of using $s, I just replace the element, with the existing element, causing it to re-initialise.
var htmldb_delete_message='"DELETE_CONFIRM_MSG"';
function fileCheck(el){
if(el.value){
var validFile = false;
var validExtensions = ["csv"];
var filename = el.value;
var fileExtIndex = filename.lastIndexOf(".");
var fileExt = filename.substring(fileExtIndex+1, filename.length);
for(i = 0; i < validExtensions.length; i++){
if(validExtensions[i] == fileExt){
validFile = true;
break;
if ( !validFile || fileExtIndex == -1) {
alert("Invalid Extension. Permitted files must end with: " + validExtensions.toString());
var htmlContents = el.outerHTML || new XMLSerializer().serializeToString(el);
$('#P16_BINARY').replaceWith(htmlContents);
}(obviously, replacing what you need to, to suit your page - i prefer scotts idea of passing in supported file types in the function, so would just pass in an array instead; but this is just for demonstration)
with an onchange="checkFile(this)" on the element attributes.
On a slightly un-related note, I found out IE doesn't support the wonderful indexOf function on arrays, that checks for the existence of the value in an array. Sucks.
Edited by: trent
Ah well, jQuery is there, maybe i should use that for searching arrays in the future.
http://api.jquery.com/jQuery.inArray/
Edited by: trent
Forgot a demo link, for csv files: http://apex.oracle.com/pls/apex/f?p=45448:16
Edited by: trent
Modify function. Didn't work in Firefox -
No luck trying to extract .inf files from drivers downloaded as zip files
Hi,
I am trying to extract .inf files from drivers downloaded as zip files from the Toshiba website, but I'm having no luck.
I am trying to deploy images using WDS on server 2008 and need the inf files for this to succeed, does anyone have the answer to this problem.
thanks in advance.Hi
I found this tip:
Someone wrote this:
+You have to run the installer, wait for it to get to the first point where you click Next to continue, and then leave it sitting there. Go into your system's Temp and find the particular one with the installation files inside it that were extracted, then copy it someplace, go back to the installer and cancel it.+
You could also try this freeware application to extract the package:
http://www.legroom.net/software/uniextract -
Create Zip File In Windows and Extract Zip File In Linux
I had created a zip file (together with directory) under Windows as follow (Code are picked from [http://www.exampledepot.com/egs/java.util.zip/CreateZip.html|http://www.exampledepot.com/egs/java.util.zip/CreateZip.html] ) :
package sandbox;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
* @author yan-cheng.cheok
public class Main {
* @param args the command line arguments
public static void main(String[] args) {
// These are the files to include in the ZIP file
String[] filenames = new String[]{"MyDirectory" + File.separator + "MyFile.txt"};
// Create a buffer for reading the files
byte[] buf = new byte[1024];
try {
// Create the ZIP file
String outFilename = "outfile.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
// Compress the files
for (int i=0; i<filenames.length; i++) {
FileInputStream in = new FileInputStream(filenames);
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(filenames[i]));
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
// Complete the entry
out.closeEntry();
in.close();
// Complete the ZIP file
out.close();
} catch (IOException e) {
e.printStackTrace();
The newly created zip file can be extracted without problem under Windows, by using [http://www.exampledepot.com/egs/java.util.zip/GetZip.html|http://www.exampledepot.com/egs/java.util.zip/GetZip.html]
However, I realize if I extract the newly created zip file under Linux, using modified version of [http://www.exampledepot.com/egs/java.util.zip/GetZip.html|http://www.exampledepot.com/egs/java.util.zip/GetZip.html] . The original version doesn't check for directory using zipEntry.isDirectory()).public static boolean extractZipFile(File zipFilePath, boolean overwrite) {
InputStream inputStream = null;
ZipInputStream zipInputStream = null;
boolean status = true;
try {
inputStream = new FileInputStream(zipFilePath);
zipInputStream = new ZipInputStream(inputStream);
final byte[] data = new byte[1024];
while (true) {
ZipEntry zipEntry = null;
FileOutputStream outputStream = null;
try {
zipEntry = zipInputStream.getNextEntry();
if (zipEntry == null) break;
final String destination = Utils.getUserDataDirectory() + zipEntry.getName();
if (overwrite == false) {
if (Utils.isFileOrDirectoryExist(destination)) continue;
if (zipEntry.isDirectory())
Utils.createCompleteDirectoryHierarchyIfDoesNotExist(destination);
else
final File file = new File(destination);
// Ensure directory is there before we write the file.
Utils.createCompleteDirectoryHierarchyIfDoesNotExist(file.getParentFile());
int size = zipInputStream.read(data);
if (size > 0) {
outputStream = new FileOutputStream(destination);
do {
outputStream.write(data, 0, size);
size = zipInputStream.read(data);
} while(size >= 0);
catch (IOException exp) {
log.error(null, exp);
status = false;
break;
finally {
if (outputStream != null) {
try {
outputStream.close();
catch (IOException exp) {
log.error(null, exp);
break;
if (zipInputStream != null) {
try {
zipInputStream.closeEntry();
catch (IOException exp) {
log.error(null, exp);
break;
} // while(true)
catch (IOException exp) {
log.error(null, exp);
status = false;
finally {
if (zipInputStream != null) {
try {
zipInputStream.close();
} catch (IOException ex) {
log.error(null, ex);
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException ex) {
log.error(null, ex);
return status;
*"MyDirectory\MyFile.txt" instead of MyFile.txt being placed under folder MyDirectory.*
I try to solve the problem by changing the zip file creation code to
+String[] filenames = new String[]{"MyDirectory" + "/" + "MyFile.txt"};+
But, is this an eligible solution, by hard-coded the seperator? Will it work under Mac OS? (I do not have a Mac to try out)
p/s To be honest, I do a cross post at [http://stackoverflow.com/questions/2549766/create-zip-file-in-windows-and-extract-zip-file-in-linux|http://stackoverflow.com/questions/2549766/create-zip-file-in-windows-and-extract-zip-file-in-linux] Just want to get more opinion on this.
Edited by: yccheok on Apr 26, 2010 11:41 AMYour solution lies in the File.separator constant; this constant will contain the path separator that is used by the operating system. No need to hardcode one, Java already has it.
edit: when it comes to paths by the way, I have the bad habit of always using the front slash ( / ). This will also work under Windows and has the added benefit of not needing to be escaped. -
Hi guys,
I got a problem with my Office 365 that every time I open an office file from IE/chrome browser (i.e. click the document link and save the file to local, open it in the browser after download completed) or under a zip file, no matter it is an excel file
or word document, the Excel/Word crashes. The Excel/Word will ask me to repair the file if I open the file again. The file will be closed automatically after the repair, when I open the file again it will told me the excel/word itself has just successfully
registered and ask me to close and re-open the excel again in order to enable editing the file. This is extremely inconvenience, I have to open this file 4 times to edit my file.
Could anyone here can help me to resolve the problem?
Many thanks.Hi,
According to your description, Excel seems not crash when you opened a local Excel/Word file directly. Where do you store these file? OneDrive, SharePoint or other?
If possible, please let me see the screenshot of the error dialog.
Moreover, please open Event Viewer to check whether there's any error about the Excel/Word crash issue.
Press Win + R, type "eventvwr" in the blank box, press Enter. In the Event Viewer, browse to Windows Logs -> Application, there may be some errors after the crash.
To protect your privacy, you may send the error logs to
[email protected], we will try to find the cause.
Regards,
George Zhao
Forum Support
Come back and mark the replies as answers if they help and unmark them if they provide no help.
If you have any feedback on our support, please click "[email protected]" -
Converting html file into zip file and send email attaching zip file
Hi Experts,
I am trying to send email with attachment(html). Which contains more than 7MB. So, It is throwing an error like Size exceeded.
So, Now i need to compress the data for less than 7MB.
I decided to convert HTML File into ZIP File.
Kindly suggest me to convert the HTML file into ZIP file and sending email with attached ZIP file.
Correct answer rewarded,
Thanks & Regards,
N. HARISH KUMARHi Experts,
*// HTML_TAB converting into ZIP File
DATA : zip_tool TYPE REF TO cl_abap_zip,
filename TYPE string ,
filename_zip TYPE string .
DATA : t_data_tab TYPE TABLE OF x255,
bin_size TYPE i,
buffer_x TYPE xstring,
buffer_zip TYPE xstring.
filename = text-007. "'HTML_TAB
*describe the attachment
DESCRIBE TABLE html_tab LINES tab_lines.
bin_size = tab_lines * 255.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = bin_size
IMPORTING
buffer = buffer_x
TABLES
binary_tab = html_tab.
IF sy-subrc <> 0.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*create zip tool
CREATE OBJECT zip_tool.
*add binary file
CALL METHOD zip_tool->add
EXPORTING
name = 'FSSAI_MAIL.HTML'
content = buffer_x.
*get binary ZIP file
CALL METHOD zip_tool->save
RECEIVING
zip = buffer_zip.
CLEAR: t_data_tab[],bin_size.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = buffer_zip
IMPORTING
output_length = bin_size
TABLES
binary_tab = html_tab.
Thanks & Regards,
N. HARISH KUMAR -
"Arrange files by type" doesn't take file extension into account
After upgrading system to a Mountain Lion I was unpleasantly surprised.
The "Arrange files by type" option doesn't work any more. bmp, jpg, raw, zip, psd, tar.gz and so on - now Finder considers all these file types as "Documents" and puts them into one group. Meanwhile when i open file info it shows correct file type "Adobe Photoshop document", "Windows bitmap" etc.
Is there any way to override this behavior and make Finder arrange files by their extension?I've fixed the problem. It was related to the wrong configuration of the bundle name.
-
BIAR File error: Error in opening zip file
Hello BO Gurus,
We are using Import wizard to deploy updated universe and reports from Dev to testing and production environment.
I imported universe and reports to BIAR file in Development. But when I am trying to deploy the universe and reports to testing environment where the source will be BIAR file and destination is testing environment. IW is throwing an error :
" Failed to open the BIAR file. Reason: com.businessobjects.sdk.biar.om.internal.iw.ObjectManagerIWException:Input/Output exception occured : 'Error in opening zip file' error in opening zip file
I saved the BIAR in zip and opened the file. I could see the XML file.
Please let me how to resolve this issue.
Thanks,
Shesha NaveenI tried this option also.
Process 1 : I extracted all dev reports and working universe in a Biar file.
Result: Error as I told in previous threads.
Process 2 : I extracted only with reports
Result: Same error as I told
Process 3 : I extracted one of the report out of 17 reports.
Result: Same error.
All the test environment servers are up and running .
But I've seen three servers are stopped on Dev environment.
1)Adaptive Processing Server
2)Multidimensional analysis services
3)Webapplication Container Server.
Please let me if this effect my Biar file. and also I dont have any Web-I reports, all my reports are Desk-i reports.
Thanks in Advance,
Shesha Naveen -
Make "Files of Type" box show more file types
I am using a file dialog VI to open a windows file dialog. I have defined custom file extensions to be displayed, but they do not all show when I drop the box down. I can't add a carriage return because it takes those literally. Is there any way to
1. Expand the box
2. Make the File of type drop down "word wrap" so the user can see them all.
As a final option, is there a way to make multiple custom patterns like shown below? I'm assuming so and may have missed it in the context help, but I didn't see anything about it.
CLA, LabVIEW Versions 2010-2013
Solved!
Go to Solution.
Attachments:
filesoftype.PNG 3 KB
multiplecustom.PNG 6 KBfor(imstuck) wrote:
Call me crazy but this seems to be a very cryptic way of doing something that I feel should be built in functionality for a file open dialog VI. It, however, works and thanks to snippets I don't have to rewrite a wrapper
It is cryptic and complicated and most likely an unintended functionality that happened by accident, since that is the way you have to put the data buffer into the data structure when passing it to the Windows API function for the file dialog. What seems to happen is that LabVIEW simply puts the pointer to its string handle contents into that structure and just goes on. In that, it is actually a potential security risk since one could try to devise a string that might cause some sort of buffer overrun or similar in the Windows function.
It also most likely is something that only works on Windows (and might actually cause even havoc on other systems), since the file dialog API on other platforms is very different (in Linux it still uses it's own LabVIEW specific dialog only). If someone really had made this on intention they would rather have spent time on making this a user friendly option of the diagram node, than trying to support this Windows specific string format on non-Windows versions.
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions -
Download files from document library in zip file using javascript
Hi,
I am developing SharePoint Hosted App which needs to download all the files in the document libraries of SharePoint site in a zip folder where in that zip file each document library should be a folder, in that folder the files of that document library will
be shown. Currently I am display all the document library in a table with check boxes as shown in the below figure. Now when user selects the check boxes and click on download button, the selected document libraries along with the files should be downloaded
in a zip folder. This should be achieved through javascript. Can anyone share me the code to solve this problem.
Thanks & Regards,
Kishore
KishoreYou can use
zip.js, but the best way - implement your solution on the server-side.
[custom.development] -
Xml file to mail scenario with zip file as an attachment
Hi experts,
I have a file to mail scenario. File is in xml format.
At receiver side, first I want to zip this file and send the zip file as an attachment using mail adapter.
How can i achieve this?
Regards
DiviaHi Shabarish,
In the module tab i have specified the below beans
localejbs/AF_Modules/MessageTransformBean contentType
AF_Modules/PayloadZipBean zip
sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean mail
In the module configuration i mentioned as
Transform.ContentDescription file
Transform.ContentDisposition attachment:filename="file.xml"
zip.filenameKey contentType
zip.mode zipOne
Now i am getting the mail with zip file as an attachment.But the name of the attachment i got is MainDocument.zip
Even the file name inside the zip is MainDocument.xml.
How can i specify my own file name for both zip file and the file inside the archieve folder.Please help me.
Regards
Divia -
File to mail scenario with zip file as an attachment
Hi experts,
I have a file to mail scenario.The mail contains a zip file as an attachment.
The file in the input folder is a zip file. I want to send this zip file via email using mail adapter.How can i achieve this?Please help me to solve it out.
Regards
DiviaHi Narath,
Do check the below link it will be helpfull
Troubleshooting SOAP, HTTP and Mail Adapter Scenarios with TCPGateway
Thanks
Sampath -
File name character encoding in zipped file
Hi All,
I have the following problem: I have received a zipped file which contains a folder and file structure. The file was zipped on Windows XP with Czech language. The problem is that the folder/file names use Czech characters (codepage CP1250). The characters in filenames after unzipping the structure are corrupted.
Is there any way how to define the codepage during unzipping or, more in general, way how to convert file names in one codepage to UTF-16 used in Mac's file system?
Thanks for ideas.You might give this a try for converting the filenames after unzipping, though I think it is designed for the old Mac CE encoding rather than the Windows version:
http://support.apple.com/downloads/FileName_Encoding_RepairUtility
Otherwise the only option may be manually converting the text strings with something like TextWrangler.
Maybe you are looking for
-
Running Oracle 9i client code against an Oracle 10g install on PC
On Unix I am able to run Oracle 9i client code against an Oracle 10g install by setting ORACLE_HOME to the Oracle 10g install location and then creating a symbolic link (example: ln -fs libclntsh.so.10.1 libclntsh.so.9.0). On PC (in particular XP SP2
-
Report on infoobject and infocube
hi, I need your suggestions in this scenario: There is a cube on which i have built a report showing characteristics A and sales amount.But if the characteristic A is not sold, then it doesn't have the sales amount.So, My report shows only the info
-
Unable To Reserve Lots that are Expiring Later on the Current Date
Hi Guru's, An item has an expiry date of 12-APR-2015 23:59:59.But it got expired, from 12-APR-2015 00:00:00 the lot shows an (Available To Reserve) ATR as 0 on the Onhand Availability , although the onhand quantity and Available To Transac
-
Not able to find 0SRM_TD_LA_1 Datasource in SRM
Hi Team, We are not able to find out the 0SRM_TD_LA_1 - SRM Live Auction Transactional Data Datasource in SRM system. http://help.sap.com/saphelp_nw70ehp2/helpdata/en/55/9a39726528490a87c90bf011e34c54/content.htm Below are the package detail of SRM a
-
Incoming email replaces content with contents from old email already in inb
This morning for no apparent reason, incoming email has its content replaced with the entire content from seemingly random emails received months ago. It also replies the sender email to that attached to the old content. What could be happening here?