Spark: Update file
<p>I have a file with a list of pairs of strings. The first pair represents an id, the second pair a value.</p>

<pre><code>// saving
List&lt;Tuple2&gt; l = new ArrayList&lt;&gt;(0);
JavaRDD&lt;Tuple2&gt; rddL = javaContext.parallelize(l);
JavaPairRDD&lt;String, String&gt; rddPair = rddL.mapToPair(t -&gt; t);
rddPair.saveAsTextFile(collection+".txt");

// loading
JavaPairRDD&lt;String, String&gt; loadedCollection = JavaPairRDD.fromJavaRDD(javaContext.objectFile(collection+".txt"));
</code></pre>

<p>At some points, I need to add new lines or update entries. Therefore, I load the file, create an JavaPairRDD, but they are immutable, thus I cannot add or delete or change.</p>

<p>What is the best practice to do this? Do I need to delete the old file and save a new one everytime I want to change something?</p>