Use external files to test an application [message #1232635] |
Fri, 17 January 2014 11:42 |
Lukas Vizner Messages: 2 Registered: January 2014 |
Junior Member |
|
|
Hello,
I would like to ask for help. I am quite newbie in Eclipse. The method "process" expect 4 inputs. I have such piece of code in my MAIN class:
public Main(String[] args) {
if (args.length > 3) {
if ((args.length == 5) &&
(args[4].equalsIgnoreCase("-d"))) {
Logger.setQuiet(false);
}
try
{
process(args[0], args[1], args[2], args[3]);
} catch (UnsupportedEncodingException e) {
Logger.error("Unsupported encoding of input or output file.\n" + e.getMessage());
printEncondings(System.out);
} catch (FileNotFoundException e) {
Logger.error("Input file was not found.\n" + e.getMessage());
} catch (IOException e) {
Logger.error("Error while writing to input file.\n" + e.getMessage());
}
} else {
printHelp(System.out);
}
}
private void process(String inFile, String inEncoding, String outFile, String outEncoding){
..... some code .....
}
I run the application through a bat file, an example:
application.bat source.txt UTF8 output.txt UTF8
When I want to test the application, I compile the code and run the bat file, but I would like to debug the application in Eclipse.
How is possible to connect real input file and declarate output file when I want to debug application in Eclipse ?
Thank you very much !
Lukas
|
|
|
Re: Use external files to test an application [message #1232705 is a reply to message #1232635] |
Fri, 17 January 2014 14:36 |
|
On 01/17/2014 06:59 AM, Lukas Vizner wrote:
> Hello,
>
> I would like to ask for help. I am quite newbie in Eclipse. The method
> "process" expect 4 inputs. I have such piece of code in my MAIN class:
>
> public Main(String[] args) {
> if (args.length > 3) {
> if ((args.length == 5) && (args[4].equalsIgnoreCase("-d"))) {
> Logger.setQuiet(false);
> }
> try
> {
> process(args[0], args[1], args[2], args[3]);
> } catch (UnsupportedEncodingException e) {
> Logger.error("Unsupported encoding of input or output file.\n" +
> e.getMessage());
> printEncondings(System.out);
> } catch (FileNotFoundException e) {
> Logger.error("Input file was not found.\n" + e.getMessage());
> } catch (IOException e) {
> Logger.error("Error while writing to input file.\n" +
> e.getMessage());
> }
> } else {
> printHelp(System.out);
> }
> }
>
> private void process(String inFile, String inEncoding, String outFile,
> String outEncoding){
> .... some code .....
>
> }
>
> I run the application through a bat file, an example:
>
> application.bat source.txt UTF8 output.txt UTF8
>
> When I want to test the application, I compile the code and run the bat
> file, but I would like to debug the application in Eclipse.
>
> How is possible to connect real input file and declarate output file
> when I want to debug application in Eclipse ?
>
> Thank you very much !
>
> Lukas
There are a number of things to say about this.
The proper signature for an application main in Java (this is Java code,
right?) is:
public static void main( String[] args )
Next, if you wish to supply arguments to your application when running
in Eclipse, use the tab in the Run or Debug Configuration dialog. You
get this by right-clicking the object to be executed (e.g.: the class
your main method is in), choosing Run As... or Debug As... and then Run
or Debug Configurations.
Alternatively, you could hard-code them and not use String[] args.
Last, the location on disk relative to which any filename or file path
will be determined is your project. In other words, in a working version
of the code above, supplying "x.dat" as the input filename, execution
would assume the path to this file as being "/.../project-name/x.dat" on
your system. Similarly, if you ask your program to send data to an
output file, that file is likely going to be at the project root too,
unless you do something to cause it to be elsewhere.
I hope this is helpful.
|
|
|
|
Powered by
FUDForum. Page generated in 0.07161 seconds