Passing a file into a program using Eclipse - java

Ok so this may be a dumb question, but how do I pass a text file into my java program and likewise have a method which reads over it? I know I need to use a scanner. But I have unsuccessfully gotten the program to even recognize the text file. Any ideas?

Here's a link to one way to do it, try googling it also if this doesn't help.
Java: How to read a text file
This is a pretty common thing in java and should have many examples online.
You could also use a reader of some sort such as a bufferedReader https://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html

Related

How do I overlap sound files and save it [duplicate]

I need to merge two audio files together. Basically place one audio file on top of another and make one file. I have seen some posts on concatenating two audio files, but none on this. Thanks for any help.
I recommend you take a look at JSyn. I would discourage you to attempt to do it yourself, since it can get complicated with multiple audio formats. It supports a lot more as well.
This worked for me. Use jresources.org to help you. You could use their example: http://www.jsresources.org/examples/MixingAudioInputStream.java.html. For the org.tritonus.share.sampled.TConversionTool package, if you have problems using their library, then download their source code (http://sourceforge.net/projects/tritonus/files/): it's open source, and try using it. I tried it and it worked for me :D. I'm grateful for those guys!

suggestions for PDF topic location

Short version: Please give me a recommendation to the best place to post a question helping me convert a PDF to TEXT using JAVA programming.
Details:
I've been working on trying to change a PDF to a text file using JAVA and keep the format as close to the PDF's as possible. I've currently been using a separate,free, third party program to do the converting and then the JAVA program I made does everything else I want. I've asked around a lot of places and most recommend PDFBox which didn't work. All PDFBox did was the same thing Adobe Read X would do, which is create a huge bunch of text mess. I've tried a lot of things and spent a lot of time on this. What I'm going to do now is share one of the PDF's I been trying convert and hopefully someone can help me with some JAVA code that will help convert this. I've only really got permission to share this old file once (even thou I'm 99% sure it would be fine to share the file a few other places) and I would like post the question at the most effect spot.
Well short version (and to actually answer my actual question)
Answer is: http://stackoverflow.com
Special Thanks to #TilmanHausherr who went above and beyond by following my updates and helping me more.
Longer version.
I'm still having some formatting issues but I think I'll be able to find the rest on my own. As far as what I asked for getting the document formatted correctly using Java, that's done. As far as the question was asked this document is kind of formatted correctly it just doesn't look as pretty as some other things I've used.
After that, I got stuck because the formatting would not be correct after the conversation. I've asked around before and most said it would be too hard to explain. In the end I've had to re-learn how to attach PDFBox, trouble shoot through common problems others have had, and a single line of code from TilmanHausherr as shown in the comments helped.
When I started this project I had to learn how to get PDFBox to work with my IDE and how to arrange libs. and such. I then went on to find some old googled codes that used PDFBox to convert text from a PDF. I can't share the code used to do the converting but it takes about 4 to 5 mins to search for the original posters work. There still some modifications I had to do to their code just to get it to work, but I just followed prompts from my IDE: Eclipse.
I used this code to write to the text file instead of a Formatter.:
String textFromMain = textForAll;
try( PrintWriter out = new PrintWriter( "text.txt" ) ) {
out.println( textFromMain );
}

Questions about loading files in a program

Sup!
I'm trying to understand the concepts and differences between them to load and save files, and trying to figure out the best way to load files with a program I'm making (a database). I'm using Java, but try to help me in a more general way, if possible. Whatever help I get is a lot welcome and I thank you already for it.
I know there is "File Reader" in Java and a lot of programs use files in .txt format. I tried to open a .doc file with Notepad, just to see what would happen, and NOTHING was a text. I expected that, not everything though.
I just don't know how to make a file that is not a .txt. How that happens?
This is a big one. When I load a file, should I load all its content and let it ready for use, or should I just keep the file path and read from it as I use, using offsets and pointers starting from the file path? How should I do this either way?
In this database program of mine, some things will be images (for example), and if I were to use a .txt, I would give each image a label that the program would read and then interpret it like the label of the image, and then get the image. How could I do that?
I was sure I had more questions. If I do I ask again.
Once more, thanks in advance for the attention and help.
When it comes to the .txt bit, all "plain text" will work. Just change the file extension to .ini or .sql (if sql is installed) and change it in your filepath too.

how to read a .ptn file from java

Any one knows what .ptn file is and how to open that, just got the file from client and couldnt able to figure out what is this , searched a lot but no luck .
Also have the requirement from client that
my application should read this .ptn file from Java
is this possible ?
thanks
This seems rather obvious, but if a client is paying you to write code to read a file, you're entirely within your rights to ask what the file is, and where it comes from. If it's some internal or proprietary format, you can ask for documentation.
Of course, you might start by simply opening the file in a text editor, to see if it's just something trivial.
This wonderful web site is a repository of information about file formats; searching "PTN" brings up nothing, unfortunately, which suggests that it's nothing very common.

A follow-up question for the unzip/zip in Java

I asked a question earlier about unzip/zip using windows cmd command in Java. That turn out to be not good for a program and one would suggest using the java.util.zip to unzip/zip. After looking through some tutorial, I found out usually they just loop through the content of the zip file. If I know the name of the file I want, can I extract it explicitly without looping through the whole zip file?? Here in my case, my zip file have 2300+ entries, and I would only want one of them. Do you guys happen to know some tricks? Thank you very much!
You will find hot to decompress files at: http://java.sun.com/developer/technicalArticles/Programming/compression/
Instead of looping and extracting all files just locate file you are interested in with ZipFile.getEntry() method.
You can get a ZipEntry -object for the specific file from ZipFile-object via the getEntry-method. To access the file contents, use ZipFile's getInputStream with the ZipEntry-object.
If this is for yourself and not your program, have you considered using the jar command in the JDK for this?

Categories