Видимо я пропустил, где это объясняется, а в интеренете, говорится просто, как само собой разумеющееся:
"Попытайтесь выполнить эту программу, введя следующую строку:
Java CommandLine this is a test 100 -1"
Я не понимаю, куда подавать аргументы. У меня есть класс Solution, запускаю его в IntelliJ IDEA, просто нажимая зеленую стрелочку Run. Лошично, что в консоли программа запрашивает у меня ввод только пути файла, который я и ввожу. А как сделать запус с аргументами?
package com.javarush.task.task18.task1827;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/*
Прайсы
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader bufread= new BufferedReader(new InputStreamReader(System.in));
StringBuilder id = strSetSpasec(8); //создаём длину строки функцией
StringBuilder productName = strSetSpasec(30);
StringBuilder price = strSetSpasec(8);
StringBuilder quantity = strSetSpasec(4);
String path=bufread.readLine();
FileReader fileread=new FileReader(path);
BufferedReader bufreadfile=new BufferedReader(fileread); //считали файл в буфер
String tt=null;
Integer Max=0;
List<String> txtfile=new ArrayList<String>();
//считываем в список построчно из буфера
while ((tt = bufreadfile.readLine())!=null && (!tt.isEmpty())) {
txtfile.add(tt);
Integer forid = getid(tt.substring(0, 8)); //номер вещи из строки - метод
Max = Max > forid ? Max : forid; //ищем больший из id
}
bufread.close();
bufreadfile.close();
fileread.close();
FileWriter filewr=null;
try{
if(args[0].equals("-c")) {
filewr = new FileWriter(path, true);
id=setproduct(id, (++Max).toString());
productName=setproduct(productName, args[1]);
price=setproduct(price, args[2]);
quantity=setproduct(quantity, args[3]);
filewr.write(id.toString() + productName.toString() +
price.toString() + quantity.toString()+"\r\n");
filewr.close();
}
}
catch(ArrayIndexOutOfBoundsException e){
return;
}
}
public static StringBuilder strSetSpasec(int capacity){
StringBuilder temp=new StringBuilder(0);
for(int i=0;i<capacity;i++)
temp.append(' ');
return temp;
}
public static Integer getid(String parce){
Integer id=null;
String idstr="";
for(int i=0;i<parce.length();i++){
char ch=parce.charAt(i);
if(ch==' ')
continue;
else
idstr+=ch;
}
id=Integer.parseInt(idstr);
return id;
}
public static StringBuilder setproduct(StringBuilder tmp, String str){
for(int i=0;i<str.length();i++){
if(i==(tmp.length()))
break;
tmp.setCharAt(i,str.charAt(i)); //на позицию i пишет символ - для StringBuilder
}
return tmp;
}
}