Read in the name of the file + path using command line arguments

Hi guys,.
I'm trying to use command line arguments to read two file names. The code below works as long as the files are on the class path.
public class cmdLineArguments {
     
     public static void main(String[] args) {
          String xmlFile1 = args[0];
                String xmlFile2 = args[1];
               
          System.out.println ("\nXmlFile1: " + args[0] + "\nXmlFile2: " + args[1]);
     }
}
I would like to be able to read files that are not on the classpath as well by entering the full path as well as their names.
In other words, it works if I type:
C:\Documents and Settings\user\workspace\CmdLineArgs\src>java cmdLineArgs file1.xml file2.xml
but not if I type:
C:\Documents and Settings\user\workspace\CmdLineArgs\src>java cmdLineArgs c:\Documents and Settings\user\desktop\file1.xml c:\Documents and Settings\user\desktop\file2.xml
What would someone please explain how I can modify the code to make it work? I guess I could take both a string, change them manually (add a------it etc.), but y at - it an easier way to do it? Even a reference to a tutorial, article etc. on this matter would be much appreciated.

In addition, no idea why compile, execute code fine in Eclipse but would create an error in command line?

Thank you very much.

You must learn more about cmd.exe that is used to process the command line. The arguments passed to any program is the command line separated at whitespace so your command line arguments of

c:\Documents and Settings\user\desktop\file1.xml c:\Documents and Settings\user\desktop\file2.xml

turns into a table of

"c:\Documents", "and", "Settings\user\desktop\file1.xml", "c:\Documents", "and", "Settings\user\desktop\file2.xml"

In other words, instead of 2 arguments you actually have 6.

To bypass this file names must be enclosed in quotes

java cmdLineArgs "c:\Documents and Settings\user\desktop\file1.xml" "c:\Documents and Settings\user\desktop\file2.xml"

Tags: Java

Similar Questions

  • How to reset the windows password using command line in windows 7

    I tried net user Geek crazy * to reset the password but it has not worked. How can I reset it using the command line

    www.beingpc.com

    D:\Users\admin>NET user "xxxx xxxx" xxxx xxxx

    -> "xxxx xxxx" is a placeholder...

    Try this instead:

    NET user 'user %%nom' MyNewPassword

  • Read command line arguments to TestStand sequence start, moving within the sequence

    Start a sequence by using a batch file and add command line arguments. Example: "MySequence.seq Arg1.

    Now, within the sequence I want to read this first (and another) argument "Arg1".

    There is a stage in the ActiveX for that, giving a type (object reference) channels, see screenshot.

    Question: How to use this reference to read the argument?

    Honestly I don't think that you are using it correctly.  I think that your application in your UI Manager must handle this.  However, to answer your question:

    According to the TestStand help CommandLineArguments property is of type string.  It comes to aid of TestStand as well:

    Channels
    A collection of strings. You can get a reference to the collection of the ApplicationMgr.CommandLineArguments property, the ExpressionEdit.GetValidEvaluationTypes and ExpressionEdit.SetValidEvaluationTypes methods and the ApplicationMgr.ProcessUserCommandLineArguments event.

    Properties
    Count (read-only)
    Agenda

    Methods
    Add
    Claire
    Insert
    Delete

    Looks like you can use activeX not use Count or properties of the element to retrieve a single argument.

    Hope this helps,

  • The application's command line arguments get the path to the file in windows Explorer

    Hello

    I am trying to open a file with my labview application .exe, so I thought that windows was sending the file path double clicked in Explorer solutions in the form of argument, but all I get is the name of my exe file.

    Does anyone know how to set up windows or the application to get the double click path from the Explorer, which has the file extension has already been associated with my exe?

    Thank you!

    I'm not sure I understand, but I think you want your Labview program to open another file, as a file of perimeter?

    Have three basic choices.

    Hardcode the path with file name in your program http://zone.ni.com/reference/en-XX/help/371361K-01/glang/path_constant/

    Use the file open vi and for the user to select the file to open http://zone.ni.com/reference/en-XX/help/371361J-01/glang/file_dialog/

    Write your program to accept a http://digital.ni.com/public.nsf/allkb/17C3AD70493CE0208625666A00763364 command line argument

  • Message when you try to upgrade or install a program. "A network error occurred whtile attempted to read from the file:

    Receive the following message when you try to upgrade or install a program. "A network error occurred whtile attempted to read from the file?: MSI

    * original title - cannot open files with .msi extension *.

    You try to open this leave a link online? If yes I would like to try and save the MSI on your desktop and then try to open.

  • I tried to convert doc to the pds.  He converted all the files in you folder to the pds.  The problem is that I can't open any files without buying adobe.   I can't unconvert so now I can't read all the files?

    I tried to convert doc to the pds.  He converted all the files in you folder to the pds.  The problem is that I can't open any files without buying adobe.   I can't unconvert so now I can't read all the files?

    Hi chrism43238735,

    May I know the process to convert Doc to PDF files. If you use Acrobat to convert the files, and then with the same application you open.

    If you used another process, in this case try using the Adobe Acrobat Reader application. Adobe - Adobe Acrobat Reader DC Distribution

    Thank you

    Abhishek

  • IE7 "could not open the file: * path *.» The file exists may not

    I created a package of IE7 a while back which works great.  Apart from this little problem.  It generates an error when the user tries to open a .msg to the WebApp.  It will try to open Outlook and display the following error message.  «Could not open the file: * path *.»  The file exists may not, you don't have permission to open it, or it may be open in another program.  Right click on the folder that contains the file, and then click action to check your permissions for the folder. »

    All the other files attached to work.  PDF, html, txt, rtf, etc.  I tried to move temporary Internet files to a different location with the same result.

    Someone at - it ideas?

    Thank you!

    He was captured on Windows Server 2003 x 64 running on W7 x 64

    Also note that when users choose to save him, it opens fine.  This isn't an "acceptable workaround solution.

    Looks a lot like this one: http://blogs.vmware.com/thinapp/2011/01/locally-installed-applications-and-integration-with-virtualized-internet-explorer.html

  • Is possible to write the INSERT statement that fills two columns: 'word' and 'sense' of the file text with multiple lines - in each line is followed word that is the meaning?

    Is possible to write the INSERT statement that fills two columns: 'word' and 'sense' of the file text with multiple lines - in each line is followed word that is the meaning?

    Hello

    2796614 wrote:

    Is possible to write the INSERT statement that fills two columns: 'word' and 'sense' of the file text with multiple lines - in each line is followed word that is the meaning?

    Of course, it is possible.  According to what the text file looks like to, you can create an external table that treats the text file as if it were a table.  Otherwise, you can always read the file in PL/SQL, using the utl_file package and INSERT of PL/SQL commands.

    You have problems whatever you wantt?  If so, your zip code and explain what the problem is.

    Whenever you have any questions, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the exact results you want from these data, so that people who want to help you can recreate the problem and test their ideas.  In this case, also post a small sample of the text involved file.

    If you ask about a DML operation, such as INSERT, then INSERT statements, you post should show what looks like the tables before the DML, and the results will be the content of the table changed after the DML.

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

  • Cannot open the attachment in yahoo... says the file is used by another program... trying to open Microsoft Picture It!

    Cannot open the attachment in yahoo... says the file is used by another program... trying to open Microsoft Picture It!

    Minnie3,

    You may need to change the default program that opens the images.
    Hope that helps!

    Cody C
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Security How can I remove the copy and paste the files I used?

    Security How can I remove the copy and paste the files I used?

    I can't get rid of all the e-mail addresses I have copied and pasted.  No matter what I will always appear if I hit paste again.  This is a shared computer and I would rather not have my copy and paste the files stored on the computer, after that I quit.

    Thank you

    Hi Ron,

    You can copy or move information (for example, text and pictures) between files and programs using temporary storage called the Clipboard. The Clipboard is not visible, so even if you use it to copy and paste information, you never actually see the Clipboard when you do this.

    The Clipboard contains a block of information at a time. Whenever you copy information to the Clipboard, the old contents of the Clipboard is replaced by the new information.

    When you shut down the computer everything is stuck in the memory of the Clipboard is cleared.

    Please click the below mentioned link to get an overview of the clip board memory.

    http://Windows.Microsoft.com/en-in/Windows7/copy-information-between-files

    Answer please if you have any questions.

  • What is fledge command-line argument to control the graphics acceleration?

    Is there a command line argument to control the graphics acceleration for a JDE 5.0 Simulator?

    I would like to switch off in the command line so I can add it to the Simulator Run Eclipse IDE and the debug configuration.

    I checked their moult imaginal/Help and I have not found any that I could see that it works.

    Thank you.

    The settings are stored in a file located at

    \Documents and Settings\ [windows login name]\net\rim\fledge-2\fledge-saved.conf

    At the bottom of the appearance of file for the line:

    4
    

    Change the number 0 for no acceleration.

  • Go (argc and argv) command line argument to a LabVIEW built the shared library.

    Hello

    I correctly use this trick to create a LabVIEW application that runs on Linux without X display.

    http://digital.NI.com/public.nsf/allkb/5D6EC36DCF43343786257449006919E6

    I would like to know if it is possible to pass command line arguments (. / TEST A B C D) directly in the library shared without having to pass arguments using an array of strings that would need to write code using DSNewHandle, DSSetHandleSize, extract arguments and... (I'm not proficient in C, but if I don't have the choice, I'll do and improve my skills of C).

    int main(int argc, char *argv[])
    {
            Test(argc, argv);
            return 0;
    }
    

    Thank you

    Michel

    Well, you can always flatten it into a single string separated by a space and pass like that. Reverse basically what made the operating system, when he calls your main function with command line parameters. And while the first element of the array is always the name of the program itself you can just ignore that here, but then put shaped everything in a single string.

  • Using command line to update the certificates of fglam

    We try to change all of our FGLAMs to use a private communication to the FMS certification authority, but I'm unable to get the command line parameters to work.  The documentation is vague on the use of all parameters.

    fglam - configure - headless - fms address = https://someaddress:port ssl-enable-self-signed = false ssl-cert-name common CertName compressed

    "I receive an unrecognized command line argument ' ssl-enable-self-signed = false ssl-cert-name common = compressed CertName". "

    FMS: 5.6.10

    FGLAM: 5.6.11

    actually I take that.

    We use the compressed argument, but looking at the doc, it seems the thought that is set to true by default, else, you must specify it as false, so you may be able to remove this setting all together.

  • Open the CD compartment by using command line on Windows7?

    Hello world

    Today, I try to open a cd tray in different methods.  I open more than 4 ways successfully. But I don't know how to open a drawer of CD using command-line in windows 7? Can anyone help to success on the fifth plea.

    Any help will be greatly appreciated.

    Hello world

    Today, I try to open a cd tray in different methods.  I open more than 4 ways successfully. But I don't know how to open a drawer of CD using command-line in windows 7? Can anyone help to success on the fifth plea.

    Any help will be greatly appreciated.

    Hello

    There is no command to operate the drawer in the Windows command prompt.

    You can add a small command-line utility called Nircmd.exe that will allow you to do this, and more to use many cool commands more.

    Go to the following site.

    NirCmd v2.75:

    http://www.NirSoft.NET/utils/NirCmd.html

    Download the utility. Unzip the file and copy the Nircmd.exe file in the C:\Windows\System32 folder.

    (If you use the 64-bit Windows version, also copy the file in the SysWOW64 folder so that it also works with the 32-bit command prompt)

    After that, open the command prompt and type the following command.

    Nircmd.exe cdrom open D:

    (Where D: is the CD-ROM drive)

    See the NirCmd.chm help file for all orders in option.

    Concerning

  • I'm looking for documentation on the Firefox command line arguments.

    I'm looking for documentation on the Firefox command line arguments. I use Ubuntu.

    http://KB.mozillazine.org/Command_line_arguments

    This doesn't seem to be what you're looking for?

Maybe you are looking for