1+ import util .ConvertUtil ;
12import util .DebugUtil ;
23import util .FileCheckUtil ;
3- import util .ConvertUtil ;
44
55import java .nio .file .Files ;
66import java .nio .file .Paths ;
7+ import java .util .HashSet ;
78import java .util .Scanner ;
89
910/**
1011 * @author weloe
1112 */
1213public class Main {
1314
15+ static HashSet <String > convertMethodSet = new HashSet <>();
16+ static {
17+ convertMethodSet .add ("pdf2word" );
18+ convertMethodSet .add ("pdf2image" );
19+ convertMethodSet .add ("word2html" );
20+ convertMethodSet .add ("word2image" );
21+ convertMethodSet .add ("word2pdf" );
22+ }
23+
1424 public static void main (String [] args ) {
1525 Scanner scan = new Scanner (System .in );
1626 System .out .println ("============================" );
@@ -26,6 +36,12 @@ public static void main(String[] args) {
2636 String pathName = scan .next ();
2737 String outPath = scan .next ();
2838
39+ convertMethod = convertMethod .toLowerCase ();
40+ if (!convertMethodSet .contains (convertMethod )){
41+ DebugUtil .logf ("不存在该传换方法: " ,convertMethod );
42+ continue ;
43+ }
44+
2945 if (!Files .exists (Paths .get (pathName ))) {
3046 DebugUtil .logf ("该文件 %s 不存在" , pathName );
3147 continue ;
@@ -35,7 +51,8 @@ public static void main(String[] args) {
3551
3652 // 检查文件类型
3753 try {
38- FileCheckUtil .checkFileType (convertMethod .substring (0 , 3 ), pathName );
54+ String beforeType = convertMethod .substring (0 , convertMethod .lastIndexOf ("2" ));
55+ FileCheckUtil .checkFileType (beforeType , pathName );
3956 } catch (Exception e ) {
4057 DebugUtil .logf ("请检查需要转换的文件的类型" );
4158 continue ;
@@ -46,8 +63,9 @@ public static void main(String[] args) {
4663 ConvertUtil .convert (convertMethod , pathName , outPath );
4764 } catch (Exception e ) {
4865 DebugUtil .logf (e .getMessage ());
66+ continue ;
4967 }
50- DebugUtil .logf ("转换成功!文件路径 : %s" , outPath );
68+ DebugUtil .logf ("转换成功!输出文件路径 : %s" , outPath );
5169 }
5270
5371 scan .close ();
0 commit comments