I need to know how can i save text from a javax.swing.JTextArea using javax.swing.JFileChooser. I tried different things but i am not able to save the data from the JTextArea. And also copy from one text file to another using JFileChooser. Please help, I am relatively new to java.
Look at the Basic I/O lesson of the Java Tutorial with particular attention to Reading, Writing, and Creating Files.
For more specific advice, you would need to ask more specific questions, or any questions, for that matter.
JTextArea has read(...) and write(...) methods that you should be using.
A JFileChooser is just for getting the file name and has nothing to do with file I/O.
Copying data is a different story and Andrew has given you links to the tutorial on using file I/O.
Related
I have a web application using iText v2.1.7 to create PDFs; before anyone tries to move me to a different library, let me point out that, like most programmers, I don't choose the libraries my company uses for things, or I certainly would not use this one.
I have code that generates these PDFs; now I am to add code that takes the contents of an existing PDF and inserts it into the PDF I'm creating.
I've found examples of how to do this, but they all use files. Except for the one I'm reading, I don't have files; I'm in a web application where I don't have easy access to a place to write a file.
Can't I open the existing PDF and somehow insert its entire content into the document I'm creating, without having to write to a file?
After I do this, I will have more content to add to the document, either from another file, dynamically created content, or both, so it isn't a simple merge of my content with one existing file. I also haven't created the existing file as its own entity, to be merged with another file, though I suppose I can do that IF it's necessary.
But I was hoping there was a way (or were ways) to do this without having to reorganize my existing code. It's possible the answer is implied in one of these examples, but they don't explain the concepts behind things, so I don't know where I can put input Streams instead of file input streams, output streams instead of file output streams, etc.
I have been bumping my head against the wall with this one, have researched and pretty much tried every library suggested to me. I am currently trying to write a program in java that will extract text AND images from a pdf file and allow me to write the extracted content to a word file. I have managed to extract the content using the ICEpdf library, however the problem is that I need to be able to write the content in the exact same order as it was read. So, to clarify, I need a library that will help me keep track of where exactly in the page the text and images are situated so I can put them in the same place in my word file.
A PDF to Word converter is a horribly complex proposition.
Your best bet will probably to use Open Office to do it for you and not even try to handle the intermediate steps.
http://www.openoffice.org/api/
Look at this: Advanced PDF parser for Java
OFF:
-Also to my knowledge there is a python parser that sorta converts the pdf to html (that way you can keep track of the ordering of the objects within the pdf). I know its not java, but you might be able to use the output.
http://www.unixuser.org/~euske/python/pdfminer/index.html
I'm working on a Java program that will allow me to view images in a zip/rar file without unzipping it to a folder on my hdd. I'd like to be able to flip through them like on a normal image viewer, possibly able to zoom in/out if needed.
From what I've looked into, it'll have to be extracted even if it's just to a temporary folder, which I'm fine with as long as the program can delete it on its own after. I believe ZipFile would be something I should do more research in? Most of what I've seen deal with text documents rather than image files, so I'm not sure how to proceed in my research.
I'm looking to see if I'm on the right track or if there are any good resources/specific apis I could look into to help as I haven't done any coding in months (save for light php and html) or any java in about a year, and I've had this on the back-burner for long enough.
Thanks in advance. :)
You're on the right track with ZipFile, and I don't think you need to extract to disk before viewing the images.
A ZipFile object will give you a list of its contents with entries(). You can iterate this collection of ZipEntry objects to present a choice of which file to view, and of course filter it to known extensions if you desire.
Strangely enough it's the ZipFile object and not the the individual ZipEntry objects that will give you an InputStream for the given entry. You can read this object into a byte[] in memory and send it to the component that will be responsible for displaying the image.
One caveat is that with zip files, in order to get to the last file stored in the zip it will basically have to decompress the whole archive which can be time consuming. So it may make sense to cache files on disk or an in-memory LRU cache depending on the usage pattern.
You didn't mention if this is for a Swing application, but if it is this might be helpful for displaying the images:
http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html
I'm trying to use crawler4j to crawl websites. I was able to follow the instructions on the crawler4j website. When it is done it creates a folder with two different .lck files, one .jdb file and one .info.0 file.
I tried to read in the file using the code that I provided in this answer to read in the file but it keeps failing. I've used the same function to read text files before, so I know the code works.
I also found someone else that asked the same question a few months ago. They never got an answer.
Why can't I use my code to open and read these .lck files to memory?
Crawler4j uses BerkeleyDB to store crawl informations. See here in the source.
From the command line you can use DB utils to acces the data. Already covered in SO here.
If you want to access the data in your Java code, you simply import BerkeleyDB library (Maven instruction there) and follow the tutorial on how to open the DB.
So, I was recommended GStreamer to create video files. I was going over their tutorial for creating a video file.
The problems I encountered are:
How do I create an AVI file rather than a YUV something.
What is the source being used there?
I want to give a set of BufferedImages or anything else that will show what was going on the screen. I have previously used JPEGtoMovie provided bu the Java guys and for that I had to first save all the images to the disk as JPEG, sort them into their correct order from lexicographical order and a whole lot more.
I was planning to avoid that and that is why I was thinking of Vector<BufferedImage> or BlockingArrayQueue<BufferedImage>
Which all plug-ins do I need from GStreamer to create the AVI output?
Sorry I have been asking too many questions today. I have never worked with a media framework before and I am very dumb
The command gst-inspect will list all included elements (components).
you can produce an avi file from the pipeline: videotestsrc ! encoder ! avimux ! filesink where encoder stands for the encoding element you'd like to use
an alternative would be to use: videotestsrc ! encodebin ! filesink; here you just build a profile and encodebin will figure our what encoder and what muxer to use to create the format specified in the profile
I did not understood the part around the BufferImages. You can feed images manually to gstreamer (e.g. using [appsrc ! decodebin] instead of [videotestsrc]), but thats a last resort. There are also elements such as multifilesrc that read a sequece of images. Maybe you can give more details what you want to do (where do the source frame come from).