В файле всё работает огонь, как только на проверку -u и -d не работают!!!
Уже второй день не могу перейти на 19 лвл, спасите кто-нибудь от этой задачи)
package com.javarush.task.task18.task1828;
/*
Прайсы 2
*/
import java.io.*;
import java.util.List;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws IOException {
String filename = new Scanner(System.in).next();
//args = new String[] {"-u","3","Гуси Бегите от этой задачи", "12345", "14"}; String filename="tmp.txt";
if(args.length==5 && args[0].equals("-u")) {
FileInputStream inFile = new FileInputStream(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(inFile));
int count=0;
String tmp1="";
while((tmp1=reader.readLine())!=null){
count++;
String tmp = tmp1;
if(ID(tmp) == ID(args[1])) {
}
}
reader.close();
String newLine = needString(args[1], 8) + needString(args[2], 30) + needString(args[3], 8) + needString(args[4], 4);
ChangeLineInFile changeFile = new ChangeLineInFile();
changeFile.changeALineInATextFile(filename, newLine, count);
}
else if(args.length==2 && args[0].equals("-d")) {
FileInputStream inFile = new FileInputStream(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(inFile));
int count=0;
String tmp1="";
while((tmp1=reader.readLine())!=null){
count++;
String tmp = tmp1;
if(ID(tmp) == ID(args[1])) {
break;
}
}
reader.close();
ChangeLineInFile changeFile = new ChangeLineInFile();
changeFile.deleteALineInATextFile(filename, count);
}
}
public static String needString(String string, int max){
if(string.length()>max){
return string.substring(0,max);
}else if(string.length()<max){
String tmp="";
for(int i=0; i<max; i++){
if(i<string.toCharArray().length) tmp+=string.toCharArray()[i];
else tmp+=" ";
}
return tmp;
}else return string;
}
public static int ID(String stringID) throws IOException {
int endChar = stringID.length();
if (endChar>8) endChar=8;
if(stringID.length()<1) return 0;
else return Integer.valueOf(stringID.substring(0,endChar).replaceAll("[^0-9]", "").replace("\uFEFF", ""));
}
public static int maxID(String file) throws IOException {
int max=0;
FileInputStream inFile = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(inFile));
String tmp;
while ((tmp=reader.readLine())!=null) {
if(tmp.length()<1) break;
tmp = tmp.replaceAll("[^0-9]", "").replace("\uFEFF", "");
int tmp1=max;
if(tmp.length()>0) tmp1 = Integer.valueOf(tmp);
if (max < tmp1) max = tmp1;
}
reader.close();
inFile.close();
max++;
//return needString((max)+"",8);
return max;
}
public static void listadd(String file, List list) throws IOException {
FileInputStream inFile = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(inFile));
String tmp;
while ((tmp=reader.readLine())!=null) {
list.add(ID(tmp), tmp);
}
reader.close();
inFile.close();
}
}