title: NIO load file in an unit test from src/test/resources
body: <p><strong>The Problem</strong></p>
  
  <p>I'd like to write a data import in java with java7s NIO. The user enters the path of a file as a String and the programm try to open it by using Paths. When it want to read its DosFileAttributes an java.nio.file.NoSuchFileException: file.txt occures.</p>
  
  <p><strong>What i've found</strong></p>
  
  <p>The only answers i've found till yet is to use an resource Stream - but this seams not practicable, because the file to be loaded is provided by the user and should not be part of the jar. Or did i missunderstood it? <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResourceAsStream%28java.lang.String%29" rel="noreferrer">http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResourceAsStream%28java.lang.String%29</a></p>
  
  <p><strong>What i've got</strong></p>
  
  <p>The Setup:</p>
  
  <ul>
  <li>Maven 3</li>
  <li>Java7</li>
  <li>TestNG</li>
  <li>Spring</li>
  </ul>
  
  <p>Project Structure:</p>
  
  <ul>
  <li>src/main/java - the classes</li>
  <li>src/test/java - the testcases</li>
  <li>src/test/resources - perhaps file.txt ? actual it is there</li>
  </ul>
  
  <p>The source that loads the file:</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.IOException;
  import java.nio.charset.Charset;
  import java.nio.file.Files;
  import java.nio.file.Path;
  import java.nio.file.Paths;
  import java.nio.file.attribute.DosFileAttributes;
  import java.util.ArrayList;
  import java.util.List;
  
  import org.springframework.stereotype.Component;
  
  @Component( "fileLoader" )
  public class BufferdFileLoader
          implements FileLoader {
  
      @Override
      public List&lt;String&gt; loadFile( String path )
              throws IOException {
  
          if ( path == null || path.length() == 0 ) {
              throw new IllegalArgumentException( "path should not be null" );
          }
  
          Path file = Paths.get( path );
  
          // here the Exception is thrown
          DosFileAttributes attrs = Files.readAttributes( file, DosFileAttributes.class );
  
          if ( !attrs.isRegularFile() ) {
              throw new IOException( "could not read file, invalid path" );
          }
  
          List&lt;String&gt; result = new ArrayList&lt;String&gt;();
  
          try (BufferedReader reader = Files.newBufferedReader( file, Charset.forName( "UTF-8" ) )) {
              String line = null;
              while ( ( line = reader.readLine() ) != null ) {
                  result.add( line );
              }
          }
  
          return result;
      }
  }
  </code></pre>
  
  <p>And the Test case is as simple:</p>
  
  <pre><code>import java.io.IOException;
  import java.util.List;
  
  import javax.inject.Inject;
  
  import lombok.Setter;
  
  import org.springframework.test.context.ContextConfiguration;
  import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
  import org.testng.Assert;
  import org.testng.annotations.Test;
  
  /**
   * Class under test {@link BufferdFileLoader}
   * 
   */
  @ContextConfiguration
  public class BufferdFileLoaderTest
          extends AbstractTestNGSpringContextTests {
  
      /**
       * Class under test
       */
      @Inject
      @Setter
      private BufferdFileLoader bufferdFileLoader;
  
  
      /**
       * Method under test {@link BufferdFileLoader#loadFile(String)}
       * 
       * @throws IOException
       */
      @Test( groups = { "integration" }, enabled = true )
      public void testImportFeedsFromXMLFileWitEmptyXml()
              throws IOException {
  
          String filename = "empty-example-takeout.xml";
  
          List&lt;String&gt; list = this.bufferdFileLoader.loadFile( filename );
  
          Assert.assertEquals( list.size(), 0 );
  
      }
  
  }
  </code></pre>
  
  <p><strong>So my question is</strong></p>
  
  <p>How to load a file using NIO so it is testable with maven and also works in production environment?</p>