This question already has answers here:
Validation of files based on their file extensions
(2 answers)
Closed 9 years ago.
I want to validate file contents based on their extension. For example, a user can save a document file (.doc/.docx) as an Excel file (.xls/.xlsx). Before I get the file contents, using Java I need to validate the content type matches with that extension.
Is any one have idea about, please share your points.
There exists projects already to detect the details of a file. The file command on linux can do this for example.
A Java project called Tika might be useful to you, Tika will parse the file(s) specified on the command line and output the extracted text content or metadata to standard output.
Related
This question already has answers here:
How to read and write excel file
(22 answers)
Closed 6 years ago.
could you please anyone assist me how to read excel files datas and write into csv file using java????
Please give Code for this scenario
Thanks in Advance
Regards
Kumar
One simple solution would be to convert your excel file into a .CSV file by saving it as such. Then you could, depending on the excel table structure, read the CSV file if the table successfully saved as one.
I think reading a simple CSV-file in Java won't require any sample-coding from me since it is fairly simple if one understands the I/O operations of the Java API.
If you actually need to do that converting manually I would not go for Java here. Use VBA which is used for macro programming in Excel.
This question already has answers here:
Generate excel sheet from html tables using jquery
(4 answers)
Closed 9 years ago.
I have table that get data from java code and show that data on web page . Can i export this data in excel format using javascript?
What will be the code for that
Javascript does not interact with file Object. it requires aciveX Object that only IE has available.
you need to export it using different third party library like apache POI
Also you can anyhow use wkhtmltopdf that prints exactly same that will be available on HTML page into pdf
This question already has answers here:
Recommendations on a free library to be used for zipping files [closed]
(9 answers)
Closed 8 years ago.
I want to process password protected zipped files using Hadoop mapreduce. I was able to process unprotected zip files using ZipFileInputformat. But it doesn't support password protected zips.
Is there any Java library that provide stream access to password protected zip files or extract zip files if I can make its byte content available ? Thanks in Advance.
Assuming you can find a java library that can read password protected zip files (see this blog article for an example), you should be able to modify the current ZipFileInputFormat to use this library and then you'll just need to configure the password for each zip file via a configuration option (hopefully you don't have too many files, or all the files are protected using the same password).
It should be easy enough. Give it a try and if you run into problems, post another question - or ask author of the input format (https://github.com/cotdp/com-cotdp-hadoop is one possible implementation of ZipFileInputFormat i found via google) as to whether he can roll the update for you
This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
How to write to the SAME excel sheet using JXL API?
i am reading one excel file and validating the same. If validation is not success, i want to display some error on the same sheet. So how it can be possible? Can any one have any idea?
I guess the only way is to create a temporary file of the original file and read the temporary file. Do the validations. Open the original file for writing and display the error message. Finally delete the temporary file :-)
This question already has answers here:
Java : How to determine the correct charset encoding of a stream
(16 answers)
Closed 8 years ago.
Any idea about gettin the real encoding of a file like .html .txt .java and etc in java?
Since some source codes are not utf-8,I wantto change them to utf-8.
In general, it is not possible to always detect exactly what the character encoding of a text file is - there's nothing stored in a text file that tells you explicitly what the character encoding is. You can make some intelligent guesses, but don't expect that you'll always be able to find out exactly what the character encoding of a text file is.
The link that cebewee posted in the comments has more information on how to detect what the character encoding of a text file is.
You can use tools like UTFCast to batch convert file encoding. Just run them on all of your source files and you should be done. On linux, you can use 'iconv' to convert file encoding.