-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?

3
  • Yes. Here you have an example of reading and writing : stackoverflow.com/a/22074145/3315914 Commented Mar 12, 2014 at 20:43
  • 1
    Did you try it and see? Commented Mar 12, 2014 at 20:44
  • If you wrote a good code the answer is yes. Commented Mar 12, 2014 at 20:45

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.