How may I use this thing in Ubuntu? (My question is this part.) ................
ID: 3892591 • Letter: H
Question
How may I use this thing in Ubuntu?
(My question is this part.)
.................................................................................................................
(This part I already know)
How to specify a text file in the command line... in Java(Netbeans)
I am trying to create a program that reads from two text file, and output will go one text file. I will use Netbeans which user set up two input file like Run> Set Project Cofiguratio> Customize> Main class, Argument. I do not want to specify the file by code like (../ srsc/ txtfile.txt) it should be like that. I already made my code the problem is the argument which should be file passing.
For example,
public class YourClass {
public static void main(String[] args) {
String fileName = args[0]; // would contain "textInput.txt"
// work with fileName
}
}
...........
java YourClass arg1 arg2 arg3
^ ^ ^
index: 0 1 2
.................................................................................................................
Program: This is in java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
public class YourClass {
public static void main(String[] args) {
String fileName = args[0]; // would contain "textInput.txt"
// work with fileName
String secondFile=args[1];
System.out.println(fileName);
System.out.println(secondFile);
}
}
.........................................................
I want to use in Ubuntu. Can you help me, please?
...................................................................
Explanation / Answer
Hi Buddy,
If I understood your question correctly, then the answer would be following:
in Ubuntu System, you just hav java compiler
to get java compiler in ubuntu run following command:
sudo apt-get install -y default-jdk
-------------*************-----------------
After installation
open terminal compile your program using following command:
javac YourClass.java
// it will generate YourClass.class
Now:
java YourClass file1.txt file2.txt
-----------------------------------------------------------------------
if any queries please comment.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.