-2

I have made a plugin for this mine craft server and its a diary, you write stuff down on a .txt and you can read it in game. I set it up so you can change the directory in game and the creating files and reading them works fine on windows until I found out the sever owner is on a mac, is it possible to create file and read them the same as windows to mac?

1 Answers1

1

Java is a highly portable language. Your code will work as long as you don't place any Windows-specific assumptions in your code. For example, this is bad:

new File("C:\\My\\Directory\\File.txt");

This is better...

new File("/My/Directory/File.txt");

Better still...

new File(File.separator + "My" + File.separator + "Directory" + File.separator + "File.txt");

Best!

File file = new File(File.separator);
file = new File(file, "My");
file = new File(file, "Documents");
file = new File(file, "File.txt");

Read the JavaDocs for more info on how to accomplish your goals in a system-independent way.

64BitBob
  • 3,110
  • 1
  • 17
  • 23