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?
-
Yes. Here you have an example of reading and writing : stackoverflow.com/a/22074145/3315914rpax– rpax2014-03-12 20:43:09 +00:00Commented Mar 12, 2014 at 20:43
-
1Did you try it and see?Mike B– Mike B2014-03-12 20:44:11 +00:00Commented Mar 12, 2014 at 20:44
-
If you wrote a good code the answer is yes.vzamanillo– vzamanillo2014-03-12 20:45:22 +00:00Commented Mar 12, 2014 at 20:45
Add a comment
|
1 Answer
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.