Java Discussion Forums

There's no such thing as a stupid question. Ask. Discuss. Learn.

Java 7 similar option to java.nio.file.Files in Java 6

Hi,

I have the following piece of code that uses the java 7 features like java.nio.file.Files and java.nio.file.Paths

I am referring this example

https://zgrepcode.com/examples/java/java/nio/file/files-implementations

  public void testInsertParam() throws IOException {
String samplePath = "src/test/resources/insert/sample/FooParam.java";
String srcPath = "src/test/resources/tmp/FooParam.java";
String spoonedPath = "src/test/resources/insert/spooned/FooParam.java";
String expectedPath = "src/test/resources/insert/expected/FooParam.java";

File tmp = new File(srcPath);
Files.copy(new File(samplePath), tmp);

SniperSpoon sniperSpoon = new SniperSpoon();
sniperSpoon.compareFiles(srcPath, spoonedPath);

String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

tmp.delete();

assertEquals("should be the same", contentExpected, contentSniped);
}

Now I have to run the the same code on Java 6 , what are the best possible alternatives other than using FileReader ?

Amandeep Singh 6 months ago
  • Whitelisted Links