package com.codeski.nbt;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import com.codeski.nbt.tags.NBTCompound;

public class Main
{
	public static void main(String[] args) throws FileNotFoundException, IOException
	{
		File f = new File("Stronghold.dat");
		System.out.println("Start reading " + f.getAbsolutePath() + "...");
		NBTCompound root = new NBTReader(f).read();
		System.out.println("Finished reading " + f.getAbsolutePath() + "...");
		System.out.println();
		System.out.println("{ " + root.toJSON() + " }");
		System.out.println();
		File test = new File("test.dat");
		NBTWriter out = new NBTWriter(test);
		out.writeNBT(root);
		System.out.println("{ " + new NBTReader(test).read().toJSON() + " }");
	}
}

@@ -105,16 +105,42 @@
 ception;
+%0Aimport java.util.Scanner;
 %0A%0Aimport
@@ -195,16 +195,94 @@
  Main%0A%7B%0A
+%09public static String tabs = %22%22;%0A%09private static final boolean debug = true;%0A%0A
 %09public 
@@ -364,45 +364,445 @@
 %7B%0A%09%09
-File f = new File(%22Stronghold.dat%22
+if (debug) %7B%0A%09%09%09System.out.println(%22Please specify file to read...%22);%0A%09%09%09Scanner s = new Scanner(System.in);%0A%09%09%09NBTCompound r = new NBTReader(new File(s.nextLine())).read();%0A%09%09%09new NBTWriter(new File(%22test.dat%22)).writeNBT(r);%0A%09%09%09new NBTWriter(new File(%22test.json%22)).writeJSON(r);%0A%09%09%09new NBTWriter(new File(%22test.xml%22)).writeXML(r);%0A%09%09%7D else if (args.length == 2) %7B%0A%09%09%09// Read in a user specified file...%0A%09%09%09File in = new File(args%5B0%5D
 );%0A
+%09
 %09%09Sy
@@ -823,15 +823,9 @@
 ln(%22
-Start r
+R
 eadi
@@ -827,37 +827,39 @@
 Reading %22 + 
-f
+in
 .get
-Absolute
+Canonical
 Path() + %22..
@@ -859,24 +859,25 @@
 ) + %22...%22);%0A
+%09
 %09%09NBTCompoun
@@ -899,17 +899,18 @@
 TReader(
-f
+in
 ).read()
@@ -917,103 +917,157 @@
 ;%0A%09%09
-System.out.println(%22Finished reading %22 + f.getAbsolutePath() + %22...%22);%0A%09%09System.out.println(
+%09// Write the file to text, JSON, or XML...%0A%09%09%09File out = new File(args%5B1%5D);%0A%09%09%09String extension = args%5B1%5D.substring(args%5B1%5D.lastIndexOf('.') + 1
 );%0A
+%09
 %09%09Sy
@@ -1088,227 +1088,584 @@
 ln(%22
-%7B %22 + root.toJSON
+Writing %22 + out.getCanonicalPath
 () + %22
- %7D
+...
 %22);%0A%09%09
-System.out.println(
+%09NBTWriter nw = new NBTWriter(out
 );%0A%09%09
-File test = new File(%22test.
+%09if (extension.equalsIgnoreCase(%22
 dat%22)
-;%0A%09%09NBTWriter out = new NBTWriter(test);%0A%09%09
+)%0A%09%09%09%09nw.writeNBT(root);%0A%09%09%09else if (extension.equalsIgnoreCase(%22json%22))%0A%09%09%09%09nw.writeJSON(root);%0A%09%09%09else if (extension.equalsIgnoreCase(%22xml%22))%0A%09%09%09%09nw.writeXML(root);%0A%09%09%09else%0A%09%09%09%09System.
 out.
-writeNBT(root);%0A%09%09System.out.println(%22%7B %22 + new NBTReader(test).read().toJSON() + %22 %7D
+println(%22Cannot write file... Supported file extensions are dat, json, and xml.%22);%0A%09%09%7D else%0A%09%09%09System.out.println(%22Usage: java -jar %22 + new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getName() + %22 %3Cfile-to-read%3E %3Cfile-to-write%3E
 %22);%0A

Add command line mode and debug mode