Read .ods files with java?
hi. my new big problem is reading an .ods file, put it into a cvs file and then use a db connection to insert, update, delete etc.
i was searching for reading .ods files and place the info there into cvs files...and i think i am missing the point. i found an Api from openoffice....which i cannot seem to understand so...
did u encountered such a problem before?
a starting point would be much appreciated.
thank you.
Nohinder wrote:
:) i have looked on google , for the first step...reading an .ods file. found something about the openoffice api, and i thought there had to be a simpler way, and THEN i posted a question here. but still, thx for the idea:)Just ignore that troll. "google.com" is his stock answer for just about everything, because he's pretty much completely clueless and just likes to pretend he's helpful
Similar Messages
-
Error reading zip file in Java 6
We have a bespoke installer program that fails, intermittently, in Java 6 on Windows. After installing some files, it then fails with a stack trace like this:
java.util.zip.ZipException: error reading zip file
at java.util.zip.ZipFile.read(Native Method)
at java.util.zip.ZipFile.access$1200(ZipFile.java:29)
at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:447)
at java.util.zip.ZipFile$1.fill(ZipFile.java:230)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:141)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
at com.XXXX.trent.installer.Installer.writeStreamToFile(Unknown Source)
at com.XXXX.trent.installer.Installer.installFile(Unknown Source)
at com.XXXX.trent.installer.PatchFileInstaller.installFile(Unknown Source)
at com.XXXX.trent.installer.PatchFileInstaller.installFiles(Unknown Source)
at com.XXXX.trent.installer.UpgradeInstaller$TpfAction.run(Unknown Source)
at com.XXXX.trent.installer.UpgradeInstaller.runActions(Unknown Source)
at com.XXXX.trent.installer.UpgradeInstaller.install(Unknown Source)
at com.XXXX.trent.installer.TrentInstall$SoftwareInstallStage.install(Unknown Source)
at com.XXXX.trent.installer.TrentInstall$UpgradeInstallWorker.install(Unknown Source)
at com.XXXX.trent.installer.PatchInstall$InstallWorker.construct(Unknown Source)
at com.XXXX.trent.utils.SwingWorker$2.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)The same code works in Java 5 on the same environments that it now fails in Java 6 (1.6.0_16).
Any ideas?
Thanks.gimbal2 wrote:
it is not weird, it is a bug in the application. Don't let the upgrade from Java 5 to Java 6 make you believe otherwise.It's a singularly bad exception message though. I would have thought that something from java.util might be a bit more explicit about what the problem is.
Winston -
How to read pdf files using java.io package classes
Dear All,
I have a certain requirement that i should read and write PDF files at runtime. With normal java file IO reading is not working. Can any one suggest me how to proceed probably with sample code block
Thanks in advance.hi I also have the pbm. to read pdf file using JAVA
can any body help meWhy is it so difficult to read the thread you posted in? They say: java.io is pointless, use iText. So why don't you?
or also I want to read a binary encoded data into
ascii,
can anybody give me a hint how to do it.Depends on what you mean with "binary encoding". ASCII's binary encoding, too, basically. -
I can't open or save file with Java Web Start
Hi,
i can't open or save file with Java Web Start:
import java.io.*;
import java.util.*;
public class MetaDataFileCreator {
public String fileNameSpace = null;
public String fileName = null;
protected Properties file = null;
public MetaDataFileCreator(String fileNameSpace, String fileName) {
this.fileNameSpace = fileNameSpace;
this.fileName = fileName;
public void createMetaDataFile() {
try {
System.out.println("file METADATA");
ClassLoader cl = this.getClass().getClassLoader();
String nameFileMetaData = fileNameSpace + fileName + ".txt";
FileOutputStream fileOS = new FileOutputStream(cl.getResource(nameFileMetaData).getFile());
file = new Properties();
file.setProperty("aaaaa", "aaaa");
file.store(fileOS, "");
fileOS.close();
} catch (Exception e) {
System.out.println("Error writing metadata-file: " + e);
System.exit(1);
e.printStackTrace();
I have try also to open a file like this:
ClassLoader cl = this.getClass().getClassLoader();
file.load(cl.getResourceAsStream(nameFile));
also like this:
try {
fos = (FileOpenService)ServiceManager.lookup("javax.jnlp.FileOpenService");
fss = (FileSaveService)ServiceManager.lookup("javax.jnlp.FileSaveService");
} catch (UnavailableServiceException e) {
fss = null;
fos = null;
System.out.println("Error with JNLP");
System.exit(1);
if (fss != null && fos != null) {
try {
// get a FileContents object to work with from the
// FileOpenService
FileContents fc = fos.openFileDialog(null, null);
//FileContents newfc2 = fss.saveAsFileDialog(null, null, fc);
// get the OutputStream and write the file back out
if (fc.canWrite()) {
// don't append
os = fc.getOutputStream(false);
} catch (Exception e) {
e.printStackTrace();
also like this:
File f = new File((System.getProperty("user.home")+"x.txt").toString());
FileOutputStream fileX = new FileOutputStream(f);
OutputX = new PrintWriter(new BufferedWriter(new OutputStreamWriter(fileX, "UTF8")));
OutputX.println(....
but it doesn't work with Java Web Start.
Can someone help me?
How can I open or save file?
thank you.
SebastianoDid you specify <all-permissions/> in your JNLP file? Did you sign your code? What error are you getting?
-
Can't create log file with java.util.logging
Hi,
I have created a class to create a log file with java.util.logging
This class works correctly as standalone (without jdev/weblogic)
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.*;
public class LogDemo
private static final Logger logger = Logger.getLogger( "Logging" );
public static void main( String[] args ) throws IOException
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String dateStr = dateFormat.format(date);
String logFileName = dateStr + "SEC" + ".log";
Handler fh;
try
fh = new FileHandler(logFileName);
//fh.setFormatter(new XMLFormatter());
fh.setFormatter(new SimpleFormatter());
logger.addHandler(fh);
logger.setLevel(Level.ALL);
logger.log(Level.INFO, "Initialization log");
// force a bug
((Object)null).toString();
catch (IOException e)
logger.log( Level.WARNING, e.getMessage(), e );
catch (Exception e)
logger.log( Level.WARNING, "Exception", e);
}But when I use this class...
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.XMLFormatter;
public class TraceUtils
public static Logger logger = Logger.getLogger("log");
public static void initLogger(String ApplicationName) {
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String dateStr = dateFormat.format(date);
String logFileName = dateStr + ApplicationName + ".log";
Handler fh;
try
fh = new FileHandler(logFileName);
fh.setFormatter(new XMLFormatter());
logger.addHandler(fh);
logger.setLevel(Level.ALL);
logger.log(Level.INFO, "Initialization log");
catch (IOException e)
System.out.println(e.getMessage());
}and I call it in a backingBean, I have the message in console but the log file is not created.
TraceUtils.initLogger("SEC");why?
Thanks for your help.I have uncommented this line in logging.properties and it works.
# To also add the FileHandler, use the following line instead.
handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandlerBut I have another problem:
jdev ignore the parameters of the FileHandler method .
And it creates a general log file with anothers log files created each time I call the method logp.
So I play with these parameters
fh = new FileHandler(logFileName,true);
fh = new FileHandler(logFileName,0,1,true);
fh = new FileHandler(logFileName,10000000,1,true);without succes.
I want only one log file, how to do that? -
Read multiples files with same extension
how to read multiples files with same extension in java.
for ex : i would like to read all .DAT files from C drive using java.
How is it done- You create the filter
- You get the list of files
- You open and read each file.
For the first two above you look at java.io.File and listFiles(FileFilter filter).
For the third you find whatever input stream is appropriate from java.io.* -
Problem unzipping larger files with Java
When I extract small zip files with java it works fine. If I extract large zip files I get errors. Can anyone help me out please?
import java.io.*;
import java.util.*;
import java.net.*;
import java.util.zip.*;
public class updategrabtest
public static String filename = "";
//public static String filesave = "";
public static boolean DLtest = false, DBtest = false;
// update
public static void main(String[] args)
System.out.println("Downloading small zip");
download("small.zip"); // a few k
System.out.println("Extracting small zip");
extract("small.zip");
System.out.println("Downloading large zip");
download("large.zip"); // 1 meg
System.out.println("Extracting large zip");
extract("large.zip");
System.out.println("Finished.");
// update database
boolean maindb = false; //database wasnt updated
// download
public static void download (String filesave)
try
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new
java.net.URL("http://saveourmacs.com/update/" + filesave).openStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream(filesave);
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
byte data[] = new byte[1024];
while(in.read(data,0,1024)>=0)
bout.write(data);
bout.close();
in.close();
catch (Exception e)
System.out.println ("Error writing to file");
//System.exit(-1);
// extract
public static void extract(String filez)
filename = filez;
try
updategrab list = new updategrab( );
list.getZipFiles();
catch (Exception e)
e.printStackTrace();
// extract (part 2)
public static void getZipFiles()
try
//String destinationname = ".\\temp\\";
String destinationname = ".\\";
byte[] buf = new byte[1024]; //1k
ZipInputStream zipinputstream = null;
ZipEntry zipentry;
zipinputstream = new ZipInputStream(
new FileInputStream(filename));
zipentry = zipinputstream.getNextEntry();
while (zipentry != null)
//for each entry to be extracted
String entryName = zipentry.getName();
System.out.println("entryname "+entryName);
int n;
FileOutputStream fileoutputstream;
File newFile = new File(entryName);
String directory = newFile.getParent();
if(directory == null)
if(newFile.isDirectory())
break;
fileoutputstream = new FileOutputStream(
destinationname+entryName);
while ((n = zipinputstream.read(buf, 0, 1024)) > -1)
fileoutputstream.write(buf, 0, n);
fileoutputstream.close();
zipinputstream.closeEntry();
zipentry = zipinputstream.getNextEntry();
}//while
zipinputstream.close();
catch (Exception e)
e.printStackTrace();
}In addition to the other advice, also change every instance of..
kingryanj wrote:
catch (Exception e)
System.out.println ("Error writing to file");
//System.exit(-1);
..to..
catch (Exception e)
e.printStackTrace();
}I am a big fan of the stacktrace. -
Executing a file with Java?
Hi,
I wanted to know how I could execute a file with java. Here are a couple scenarios - let's say I am developing an anti-spyware utility and I wanted to first write a batch file, and then create it in a folder, then run it when they click "Run". Then afterwards I want to shutdown their computer.
My Mindset:
- FileWriter to create the .bat and write the Batch commands.
- Execute the batch file.
- Execute the shutdown.exe file to reboot their PC.
So my simple question is, how can I execute a file?
Thanks!
-JoshWell here is the code I have:
try
Runtime.getRuntime().exec("cmd.exe /c test.bat");
catch(IOException e1)
//NOTHING
}Now my cmd.exe is obviously in my Windows System32 folder, and my "test.bat" file is in my C:\ root directory. So I am wondering why that wont execute. I tried a fer other things too like:
Runtime.getRuntime().exec("cmd.exe c:\test.bat");that didn't work either, because you can't have a "\" in a string...
So how can I get this thing to execute the batch file? -
Is it possible to play .rm and .wma file with java?
Hello Friends,
Please tell me,
how to play .rm and .wma file with java?
Thanks,
Harsh ModhaAs far as I know, you can not play those files.
Here you have the complete list of supported formats. Hope this helps.
http://java.sun.com/products/java-media/jmf/2.1.1/formats.html
Maybe you should try to convert from wma or rm to a supported format before attempting to play it. -
How To Read RTF file in JAVA? Using iText?
How To Read RTF file in JAVA? Using iText?.....
import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.rtf.*;
public class RTF3 {
public static void main(String[] args) {
// System.out.println("This example generate a RTF file name Sample.rtf");
// Create Document object
Document myDoc = new Document();
try {
// Create writer to listen document object
// and directs RTF Stream to the file Sample.rtf
RtfWriter2.getInstance(myDoc, new FileOutputStream("Sample.rtf"));
// open the document object
myDoc.open();
// Create a paragraph
Paragraph p = new Paragraph();
p.add("Helloworld in Rtf file..amazing isn't");
// Add the paragraph to document object
myDoc.add(p);
catch(Exception e) {
System.out.println(e);
//close the document
myDoc.close();
Exception in thread "main" java.lang.NoSuchMethodError: com.lowagie.text.Rectangle.width()F
at com.lowagie.text.rtf.document.RtfPageSetting.rectEquals(RtfPageSetting.java:433)
at com.lowagie.text.rtf.document.RtfPageSetting.guessFormat(RtfPageSetting.java:362)
at com.lowagie.text.rtf.document.RtfPageSetting.setPageSize(RtfPageSetting.java:341)
at com.lowagie.text.rtf.RtfWriter2.setPageSize(RtfWriter2.java:248)
at com.lowagie.text.Document.open(Unknown Source)
at view.RTF3.main(RTF3.java:23)
CAN you HELP me?import com.lowagie.text.Document;
import com.lowagie.text.rtf.parser.RtfParser;
import java.io.FileInputStream;
String inputFile = "sample.rtf";
Document document = new Document();
document.open();
RtfParser parser = new RtfParser(null);
parser.convertRtfDocument(new FileInputStream(inputFile), document); -
How to use parameter file with java
Is it possible to use a parameter file with Java, and is there any class/method to make it easy to call and use these parameter from a text file, other than scanning the whole text file manually as we can do normally with visual basic/c++, so we can call the program with the parameter file, like java testing c:\\testing.ini
If I understand you correctly, you may be looking for a properties file. This is basically a text file that contains pairs of strings in the form:
parameter1=value1
parameter2=value2
parameter3=value3
...etc.
and the values are retrieved using the java.util.Properties class - see:
http://java.sun.com/j2se/1.3/docs/api/java/util/Properties.html
Sample use://Call chis method once, to load the props file.
//props file is called "demo.properties", and is
//in a directory that is included in the classpath
private void loadMyProperties() throws Exception
InputStream stream = getResourceAsStream("/demo.properties");
if(stream == null)
throw new Exception("stream is null!");
demoProperties = new Properties();
demoProperties.load(stream);
stream.close();
// Then you can retrieve properties in your code using:
String param3 = demoProperties.getProperty("parameter3");
//...etc -
Hi,
I have a VSAM file and I got to read this file using JAVA and extract the data from this file .
Is there any way out ? Please help me out.
Thanks .You can get an evaluation copy of WebSphere Information Integrator Classic Federation for z/OS v8.2. This will include JDBC clients for Windows and Unix platforms as well as a z/OS data server component that can access the VSAM data. .
There are two ways to order an evaluation copy:
Through the IBM zSeries account rep
Via the Shop zSeries Web site -
Hi,
can any one help me on how to read pdf files in java using itext. I have written some piece of code but it is of no use. It is giving some garbage.
import java.io.*;
import java.util.*;
import java.lang.*;
import com.lowagie.text.pdf.PdfReader;
public class PdfAccess
public static void main(String[] args)
try {
String pdfFile = args[0];
PdfReader reader = new PdfReader(pdfFile);
int pageCount = reader.getNumberOfPages();
System.out.println(pageCount);
String content = " ";
for(int i=1;i<=pageCount;i++) {
byte[] pageContent = reader.getPageContent(i);
content = content+(pageContent.toString());
System.out.println(content.trim());
} catch(Exception e) { }
can any one help me on how to get contents of the file. Are there examples avalilable??* Try this by PDFBOX , it will execute well as per ur request..........
public void getPdfText(String fileName) throws IOException {
StringWriter sw = new StringWriter();
PDDocument doc = null;
try {
doc = PDDocument.load(fileName);
PDFTextStripper stripper = new PDFTextStripper();
stripper.setStartPage(1);
stripper.setEndPage(Integer.MAX_VALUE);
stripper.writeText(doc, sw);
OutputStream out=new FileOutputStream(new File("d://PDFText.txt"));
PrintStream write=new PrintStream(out,true,"UTF-8");
write.print(sw.toString());
//System.out.println(sw.toString());
} finally {
if (doc != null) {
doc.close();
Can..Can...If we Try...! -
I can't read a file with the ext PDF the sender informed me that the file was reset to PDF.
I can't read a file with the .ext PDF the sender informed me that the file was reset to PDF. But when I tried to open it the caption box informed me"the file is not in PDF format. I suspect the sender simply changed the file .ext which is why I can't open it! What can I do about it! I am working on an iPad.
Thanks
Mr Jim LapthornIf the document is not, in fact, a PDF, then you will need to get your sender to provide a PDF.
Can you open this document in any other application? -
I have a problem with the mac can not read video files with the extension IMOD. How can I solve this problem?
By doing a Google search.
Maybe you are looking for
-
How to add an attachment to an e-mail. With out it showing up and the end of a e-mail.
How to add an attachment to a e-mail. With out it showing up at the end of the e-mail.
-
Acrobat moves images in word booklet
The very first pdf I try to create with acrobat 8 under vista moves my illustrations all over the document. The original is a Word 2007 bookfold booklet. In the pdf, illustrations are moved all around pages over and under text. The resulting document
-
Cannot get miroring to work on iPad 1 wit Apple TV 2
Anyone else had the same issue?
-
My client has been reportng issues to me about when some people try to submit an application on their site that they recieve the error message "Image Verification Error". I had submitted a ticket to BC about this and was informed that there was some
-
I want to make another account but will I lose all my songs
I want to make another account but will I lose all my songs ?