没有找到方法的符号

时间:2015-11-10 20:52:57

标签: java symbols

我正在为类执行此Java分配,并且由于某种原因,此方法一直说该符号无法找到。下面的代码块是给我错误的。不完全确定为什么,因为我逐字地遵循了这本书,并没有提到它编译错误(通常有迹象表明要查找)

我将其余的作业添加到帖子中。我不确定它是否相对,因为我在写下现在正在发布的下半部分之前得到了错误。我不确定错误是否与在实际定义方法之前调用方法有关,但我尝试切换顺序,并且在编译时没有任何区别。

import java.nio.file.*;
import java.io.*;
import java.nio.channels.FileChannel;
import java.nio.ByteBuffer;
import static java.nio.file.StandardOpenOption.*;
import java.util.Scanner;
import java.text.*;

public class CreateFilesBasedOnState
{
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);

        Path inStateFile = Paths.get("InStateCusts.txt");
        Path outOfStateFile = Paths.get("OutofStateCusts.txt");

        final String ID_FORMAT = "000";
        final String NAME_FORMAT = "    ";
        final int NAME_LENGTH = NAME_FORMAT.length();
        final String HOME_STATE = "WI";
        final String BALANCE_FORMAT = "0000.00";
        String delimiter = ",";

        String s =   ID_FORMAT + delimiter + NAME_FORMAT + delimiter
                   + HOME_STATE + delimiter + BALANCE_FORMAT
                   + System.getProperty("line.seperator");

        final int RECSIZE = s.length();

        FileChannel fcIn = null;
        FileChannel fcOut = null;
        String idString;
        int id;
        String name;
        String state;
        double balance;
        final String QUIT = "999";

        createEmptyFile(inStateFile, s);
        createEmptyFile(outOfStateFile, s);
        try
        {
            fcIn = (FileChannel) Files.newByteChannel(inStateFile,
                                                      CREATE,
                                                      WRITE);

            fcOut = (FileChannel) Files.newByteChannel(outOfStateFile,
                                                       CREATE,
                                                       WRITE);

            System.out.print("Enter customer account number >> ");
            idString = input.nextLine();
            while (!(idString.equals(QUIT)))
            {
                id = Integer.parseInt(idString);

                System.out.print("Enter name for customer >> ");
                name = input.nextLine();
                StringBuilder sb = new StringBuilder(name);
                name = sb.toString();

                System.out.print("Enter state >> ");
                state = input.nextLine();

                System.out.print("Enter balance >> ");
                balance = input.nextDouble();
                input.nextLine();
                DecimalFormat df = new DecimalFormat(BALANCE_FORMAT);

                s =   idString + delimiter + name + delimiter + state
                    + delimiter + df.format(balance)
                    + System.getProperty("line.separator");

                byte[] data = s.getBytes();
                ByteBuffer buffer = ByteBuffer.wrap(data);

                if (state.equals(HOME_STATE))
                {
                    fcIn.position(id * RECSIZE);
                    fcIn.write(buffer);
                }
                else
                {
                    fcOut.position(id * RECSIZE);
                    fcOut.write(buffer);
                }

                System.out.print(  "Ener next cusomter account number or "
                                 + QUIT + " to quit >> ");

                idString = input.nextLine();
            }
            fcIn.close();
            fcOut.close();
        }
        catch (Exception e)
        {
            System.out.println("Error message: " + e);
        }
    }

    public static void createEmtpyFile(Path file, String s)
    {
        final int NUMRECS = 1000;

        try
        {
            OutputStream outputStr
                = new BufferedOutputStream(Files.newOutputStream(file
                                                                 , CREATE));

            BufferedWriter writer
                = new BufferedWriter(new OutputStreamWriter(outputStr));

            for (int count = 0; count < NUMRECS; ++count) {
                writer.write(s, 0, s.length());
            }
            writer.close();
        }
        catch (Exception e)
        {
            System.out.println("Error message: " + e);
        }
    }
}

0 个答案:

没有答案