William Roberts
William Roberts

Reputation: 329

FileReader file not found Mac

I'm trying to use FileReader on Mac. I've created a FileReader as:

FileReader reader = new FileReader("~\\Documents\\workspace\\ProjectAMChart\\amcharts_3.11.1.free\\amcharts\\amcharts.js");

But for some reason, I always get a FileNotFoundException. How am I supposed to enter the proper file path on a Mac?

Upvotes: 0

Views: 841

Answers (2)

Jim Garrison
Jim Garrison

Reputation: 86774

Two problems:

  1. Use forward slashes on a Mac. In fact, always use forward slashes, the system should take care of substituting the correct delimiter, even on Windows.
  2. ~ is a shell metacharacter. Use the user.home system property instead.

i.e.

String userHome = System.getProperty("user.home");
FileReader reader = new FileReader(
    userHome + 
    "/Documents/workspace/ProjectAMChart/amcharts_3.11.1.free/amcharts/amcharts.js");

Upvotes: 2

Noah Gary
Noah Gary

Reputation: 960

You should be using single forward slashes not double backslashes.

EX: "/Documents/workspace/ProjectAMChart/amcharts_3.11.1.free/amcharts/amcharts.js"

Upvotes: 0

Related Questions