Hello. I am making a Minecraft launcher and I have run into a problem. It can start MC fine. But that would only work for one user so I then tried to get it to read a text file to get the username. If it couldn't find the file it would create it. This didn't work. This is my code:
If anybody could help, that would be great!
Thanks in advance,
Curly
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class launcher { public static BufferedReader in; public static String name = "Player"; final static String fileName = "name.txt"; final static File parentDir = new File("%APPDATA%\\.minecraft"); public static File file = new File(parentDir, fileName); public static String c = "java -Xmx1024m -cp \"%APPDATA%\\.minecraft\\bin\\minecraft.jar;%APPDATA%\\.minecraft\\bin\\lwjgl.jar;%APPDATA%\\.minecraft\\bin\\lwjgl_util.jar;%APPDATA%\\.minecraft\\bin\\jinput.jar\" -Djava.library.path=\"%APPDATA%\\.minecraft\\bin\\natives\" net.minecraft.client.Minecraft \"" + name + "\""; public static void main(String[] args) { checkUser(); } private static void runMC() { try { Runtime.getRuntime().exec("cmd /c" + c); } catch (IOException e) { e.printStackTrace(); } } private static void checkUser() { try { in = new BufferedReader(new FileReader("%APPDATA%.minecraft/name.txt")); name = in.readLine(); runMC(); } catch (FileNotFoundException e1) { e1.printStackTrace(); createFile(); } catch (IOException e1) { e1.printStackTrace(); } } public static void createFile(){ parentDir.mkdir(); try { file.createNewFile(); System.out.println("Created"); checkUser(); } catch (IOException e) { e.printStackTrace(); } } }
If anybody could help, that would be great!
Thanks in advance,
Curly