@@ -0,0 +1,2612 @@
+/*%0A * To change this template, choose Tools %7C Templates%0A * and open the template in the editor.%0A */%0A%0Apackage edu.stuy.util;%0A%0Aimport com.sun.squawk.io.BufferedReader;%0Aimport com.sun.squawk.microedition.io.FileConnection;%0Aimport com.sun.squawk.util.StringTokenizer;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport javax.microedition.io.Connector;%0A%0A/**%0A * Reads and parses text files on the cRIO. This is useful for quickly adjusting tuning values using FTP, such as for PID.%0A * Place the '#' character before comments.%0A *%0A * @author Kevin Wang%0A */%0Apublic class FileIO %7B%0A    private static StringBuffer log = new StringBuffer(%22%22);%0A%0A    /**%0A     * Returns the contents of a file on the root directory of the cRIO, getting rid of comments and trimming whitespace.%0A     * @param filename The name of the file to read.%0A     * @return The contents of the file.%0A     */%0A    private static String getFileContents(String filename) %7B%0A        String url = %22file:///values/%22 + filename;%0A        String contents = %22%22;%0A        try %7B%0A            FileConnection c = (FileConnection) Connector.open(url);%0A            BufferedReader buf = new BufferedReader(new InputStreamReader(c.openInputStream()));%0A            String line = %22%22;%0A%0A            boolean lineRead = false;%0A            while ((line = buf.readLine()) != null) %7B%0A                lineRead = false;%0A                if (line.charAt(0) != '#') %7B%0A                    for (int i = 0; i %3C line.toCharArray().length; i++) %7B%0A                        if (line.toCharArray()%5Bi%5D == '#') %7B%0A                            contents += line.substring(0, i).trim() + %22%5Cn%22;%0A                            lineRead = true;%0A                            break;%0A                        %7D%0A                    %7D%0A                    if (lineRead == false) %7B%0A                        contents += line + %22%5Cn%22;%0A                    %7D%0A                %7D%0A            %7D%0A            c.close();%0A        %7D%0A        catch (IOException e) %7B%0A        %7D%0A        return contents;%0A    %7D%0A%0A    /**%0A     * Create an array of doubles using values in a text file. Each line in the file corresponds to one element in the array.%0A     * @param filename The name of the file to read.%0A     * @return The array of values in the file.%0A     */%0A    public static double%5B%5D getArray(String filename) %7B%0A        String raw = getFileContents(filename);%0A        StringTokenizer st = new StringTokenizer(raw);%0A        double%5B%5D array = new double%5Bst.countTokens()%5D;%0A        int i = 0;%0A        while (st.hasMoreTokens()) %7B%0A            array%5Bi++%5D = Double.parseDouble(st.nextToken());%0A        %7D%0A        return array;%0A    %7D%0A%7D%0A

Add FileIO.