I am not a programmer so maybe my question seem very fundamental.
I have to run the the code in the link below to get an output file:
https://github.com/matsim-org/pt2matsim/blob/master/src/main/java/org/matsim/pt2matsim/run/Gtfs2TransitSchedule.java
This code gets an input (a folder containing some text files related to open street map) and also in the code I have to specify a coordinate system (in my case is EPSG:3857) and I think also I have to specify a path fot the output file.
Unfotunately I don't know how I should specify the input file and also how I should edit my desired coordinate system. Also I have to mention these are written as args[0], args[1], args[2] and args[4] in the code.
in IntelliJ, go to Run, edit configuration,
in Program arguments you have to write the argumnet values or paths and seperate them by space
for example if my first argument is a zip folder in Drive C and my second argument is a date then I should write like below:
C://Folder//A.zip 2022.09.27
Related
I wanna know if It's possible to add/remove code to a .jar file.
Here's my case:
I have a program to organize some pdf files by company, type and date in a determined directory. But when I parse some of the pdf file the company name may be incorrect, mostly because of the way the pdf was generated.
the company name in the file pdf is:
COMPANY & MAN'S
but when converted it might outputs:
CO MPA NY & MAN S
Knowing this I have blocks to every file type to handle this kind of exception.
is this way:
static String DSN(String EDIT_DSN)
{
EDIT_DSN = EDIT_DSN.replaceAll("CO MPA NY & MAN S", "COMPANY & MAN'S");
return EDIT_DSN;
}
What I'm trying to do is create another piece of code that is able to add/edit/remove lines to this blocks. Is it possible? if it is, how should I do it?
Simple: you don't hard code these strings in your code.
Instead, you put the strings into a text file (for example a Java property file).
Then your "mapper" code simply reads the mappings from such text files. So you don't have to change your Java classes, just feed different text files to it.
I am trying to use the "Program Arguments" field in Eclipse (using java, on a mac), but whenever I enter an argument, it treats the argument like a file. I'm getting the same error no matter what. For example, if I input AL into the command line, I get the following error:
I/O exception while reading: ......./AL (No such file or directory)
I'm assuming I didn't set something up right and I was wondering how to set the command line up? I have made sure that I have the correct file, the correct method, and the pathway (the ....'s) is valid. Not really sure why this isn't working and having a hard time finding answers online.
EDIT: I added a picture of the full program and output that I am getting. For the arguments I put an "a" followed by a return key and a "b".
In C++, the file of the source code and current line number is decided by FILE and INLINE, which is decided at compiling time, is there any method in Java that could do the similar thing? The file and line number is decided at compiling time instead of runtime? this will be convenient for log. I kind of doubt that use runtime method to detect these information will decrease the performance.
You could use Thread.getStackTrace() and something like
System.out.println(Thread.currentThread().getStackTrace()[1]);
Output includes the current method and line number (if debugging was compiled in).
For example,
com.stackoverflow.Main.main(Main.java:23)
In most other languages / operating system I've worked with, a statement like
File f = new File(....);
would attempt to open the file, and either create one if it didn't exist, or return an error code if it was missing. So, what happens in java.io? I'd like to understand the mindset of the run time engine. Can I actually get a handle to a non-existent file? Dose the java run time engine hold off on making the file until the 1st time I write to it? If not, shouldn't
if(f.exists()) {…}
always be “true”?
- any comments welcome - Joe
As described in the Javadoc, java.io.File represents a path, not a file. Bad naming. Think of operations on File as path operations, because that's what they are. Unless something specifically says that it creates a file at a given path, it doesn't.
You can create a File by creating a reference to a non existing File. If you pass that File to a FileOutputsteam the Stream will create the File on your drive.
So if you cant be certain that the File doesnt exist you need to be able to check its existence with f.exists() othwerwise you wouldnt be able to make an intelligent decision on how to proceed
From the Android Developers official documentation you can read that a File is:
An "abstract" representation of a file system entity identified by a
pathname.
The actual file referenced by a File may or may not exist. It may
also, despite the name File, be a directory or other non-regular file.
I have a class (called LogCopy) I've written which when I run it in Eclipse with the 4 parameters it's supposed to have, in the correct format, surprise, surprise, runs perfectly fine. The trouble is, I need to .jar it up to put onto a live system & that's where it gets squirly. The parameters are 2 datetime stamps & 2 filenames. It's being developed & executed on a Windows system so the parameters I've supplied to test with are:
2011-03-20|10:21:20 2011-03-20|10:21:21 F:\somepath\logfile.txt F:\somepath\logfileoutput.txt
Now, putting those into a Run Configuration in Eclipse gets the desired response. If I remove a parameter or put in a value that isn't a valid date or a readable input file or a locked output file, it throws exceptions as I've set it up to do, all well & good. But when I jar it up using maven, and run it with the 4 parms as they're supposed to be I get the cryptic
The filename, directory name, or volume label syntax is incorrect
Strangely though I still get the expected error messages when I deliberately mess up the parameters, so
java -jar LogCopy-0.0.1-SNAPSHOT-jar-with-dependencies.jar parm1 parm2 parm3 parm4
gets an error log entry for each thing that's wrong about the parameters - that the dates aren't valid dates, the filenames aren't referring to files that can be used, and a little precis of the command's syntax so the user can correct what they've entered.
How come the valid filenames are giving this weird error message? I've tried entering the filenames in various formats, using forward slashes, backslashes, escaped backslashes, all sorts, but they all give the same (non programmed by me) error message. What gives?
I sussed it - & you're all going to think I've been a total noob about this & you'd be right. One of those "D'OH!!" moments. Turns out the parms only work properly if passed in as strings in double quotes, so:
java -jar LogCopy.jar "2011-05-04|10:05:23" "2011-05-04|10:05:26" "C:\dir\fromfile.txt" "C:\dir2\tofile.txt"
works, while without the double quotes Java mis-parses the parameters & appears to take part of the date as a filename.