java - Moving files between folders based on file name -


I tried some code to run some priority files from one folder to another (i.e. file with the first name Should be transferred first)

  string option 1 = "ww document"; String option 2 = "OEM-document"; ArrayList & LT; File & gt; InsertOrder1 = New ArrayList & lt; File & gt; (); ArrayList & LT; File & gt; InsertOrder2 = New ArrayList & lt; File & gt; (); ArrayList & LT; File & gt; InsertOrder3 = New ArrayList & lt; File & gt; (); String bassdire = "d: \\ vignesh \\ levfoulder"; String destDir = "D: \\ vignesh \\ leftfolder \\ testFolder"; File initialization = new file (basedear); (For File File: Forward: Initial Location.List Files ()) {String Filename = FileTomoveGetname (); If (fileToMove.getName () ends (".jar")) {if (fileName.contains (choice1)) {insertOrder1.add (fileToMove); } And if (fileName.contains (choice2)) {insertOrder2.add (fileToMove); } And {insertOrder3.add (fileToMove); }}} InsertOrder1.addAll (insertOrder2); insertOrder1.addAll (insertOrder3); Iterator & LT; File & gt; ITER = insertOrder1.iterator (); While (iter.hasNext ()) {file filein order = iter.next (); System.out.println ("files run -" + fileInOrder.getName ()); File destLocation = new file (destDir + File.Sseparator + fileInOrder.getName ()); FileUtils.moveFile (fileInOrder, destLocation); }}   

This code can work fine. But my requirement is that the priority name can be given as the property entry in the form of values ​​separated by a comma.

In this way

  string value = "W.Document, OEM-document, WTPart, EPMDocument"; String [] liked = value.split (","); (Int i = 0; i & lt; choice.length; i ++) {}   

Now my position is to me like [i] According to the requirement the condition needs to be validated and that in the array list, I have to move them. How do I write a condition for many options here? And I have to keep them in order and then move on.

In addition to that, there will be files in that folder with different names that are not included in the choice and I have to add those people at the end of my array list.

Please suggest me an idea.

You can use the map for each choice:

  Maps & lt; String, arrelisted & lt; File & gt; & Gt; Map = new hashmark for (string c: likes) map.put (c, new arrelist  ()); (For File File: Forward: Initial Location.List Files ()) {String Filename = FileTomoveGetname (); If (fileToMove.getName (). EndsWith (".Jar")) {string CH = findChice (fileName); If (ch! = Null) {map.get (ch) .add (fileName); } ...} String Search Choice (strings) {for (string c: likes) if (s.contains (c)) return c; Return tap; }    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -