Note that there are some explanatory texts on larger screens.

plurals
  1. POSearch and Replace in a file using arraylist, Java
    primarykey
    data
    text
    <p>I wrote the below part of the code but I couldn't bind the arraylist with search and replace so my csv file is as like below 1/1/1;7/6/1 1/1/2;7/7/1</p> <p>I want to search the file 1.cfg for 1/1/1 and change it to 7/6/1 and 1/1/2 change to 7/7/1 and it goes so on.</p> <p>Thank you all in advance</p> <p><strong>It's now only printing in a new file only the last line of the old File</strong></p> <pre><code>import java.io.*; import java.util.ArrayList; import java.util.List; public class ChangeConfiguration { /** * @param args * @throws IOException */ public static void main(String[] args) { try{ // Open the file that is the first // command line parameter FileInputStream degistirilecek = new FileInputStream("c:/Config_Changer.csv"); FileInputStream config = new FileInputStream("c:/1.cfg"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(config); DataInputStream degistir = new DataInputStream(degistirilecek); BufferedReader br = new BufferedReader(new InputStreamReader(in)); BufferedReader brdegis = new BufferedReader(new InputStreamReader(degistir)); List&lt;Object&gt; arrayLines = new ArrayList&lt;Object&gt;(); Object contents; while ((contents = brdegis.readLine()) != null) { arrayLines.add(contents); } System.out.println(arrayLines + "\n"); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { //Couldn't modify this part error is here :( BufferedWriter out = new BufferedWriter(new FileWriter("c:/1_new.cfg")); out.write(strLine); out.close(); } in.close(); degistir.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload