title: how to read file names under directory(local file system/hdfs) using flink java api
body: <p>I am new to Flink . Actually I am trying to read files and csv conversion through flink java api.</p>
  
  <p>As per our requirement .
  a) Need to pass folder as a input argument , output argument as a csv file name
  b) Need to read files from local file system/HDFS 
  c) Write the same data to csv</p>
  
  <p>My code:</p>
  
  <pre><code>public class WriteToCSV {
  
      public static void main(String[] args) throws Exception {
          final ParameterTool params = ParameterTool.fromArgs(args);
          final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
          env.getConfig().setGlobalJobParameters(params);
          List&lt;String&gt; paths = new ArrayList&lt;String&gt;();
          File dir = new File("C://");
          for (File f : dir.listFiles()) {
                paths.add(f.getName());
          }
          DataSet&lt;String&gt; data = env.fromCollection(paths).rebalance();
  
          DataSet&lt;Tuple2&lt;String, Integer&gt;&gt; counts = 
                      // split up the lines in pairs (2-tuples) containing: (word,1)
                      data.flatMap(new MySplitter()).groupBy(0).sum(1);
  
          System.out.println(" data -:"+data);
          data.print();
          counts.writeAsCsv("C://new.csv");
      }
  }
  
  
  class MySplitter implements FlatMapFunction&lt;String, Tuple2&lt;String, Integer&gt;&gt; {
  
      public void flatMap(String value, Collector&lt;Tuple2&lt;String, Integer&gt;&gt; out) {
          // normalize and split the line into words
          String[] tokens = value.split("\\W+");
  
          // emit the pairs
          for (String token : tokens) {
              if (token.length() &gt; 0) {
                  out.collect(new Tuple2&lt;String, Integer&gt;(token, 1));
              }
          }
      }
  }
  </code></pre>
  
  <p>I am able to get the file names (data.print()) . but csv is not creating ,no exception in the server console.</p>