title: How to extract part of file name of a CSV file in Java
body: <p>I have a CSV file and I want to extract part of the file name using Java code.</p>
  
  <p>For example if the name of the file is --> <code>StudentInfo_Mike_Brown_Log.csv</code></p>
  
  <p>I want to be able to just extract what is between the first two <code>_</code>'s in the file name. Therefore in this case I would be extracting <code>Mike</code></p>
  
  <p>So far I am doing the following:</p>
  
  <pre><code>    String fileName = "C:\\User\\StudentInfo_Mike_Brown_Log.csv";
      File file = new File(fileName);
  
      String extractedInfo= fileName.substring(fileName.indexOf("_"), fileName.indexOf("."));
      System.out.println(extractedInfo);
  </code></pre>
  
  <p>This code currently gives me <code>_Mike_Brown_brown_Log</code> but I want to only print out <code>Mike</code>.</p>