由于未知原因抛出IO异常

时间:2015-03-20 05:38:16

标签: java ios java.util.scanner ioexception

所以我添加了一个名为userSettings的新扫描程序,让用户有机会编辑一些选项。但是现在我的程序在下面的星号区域引发了一个io异常。我知道如何使用usersettings扫描仪有问题,但我不知道是什么。

//throw ioexception to handle file issues
public static void Create() throws IOException 
{   
    Scanner userSettings = new Scanner(System.in);
System.out.println("Hello! Welcome to JJJJJ's Task Management  Systems.");
    System.out.print("Would you like to enter settings? yes/any key:");
    String settings = userSettings.next();
    if(settings.equals("yes"));
    {
        settings();
    }
    userSettings.close();

    try
    {   

        File tasklist = new File("bin/tasklist.txt");
        tasklist.createNewFile();

        FileWriter writer = null;

        // creates a FileWriter Object
        if(tasklist.equals(true))
        {
            writer = new FileWriter(tasklist);
        }
        else
        {
            writer = new FileWriter(tasklist, true);
        }

        ListTasks(writer);

        taskInput.close();
        userContinue.close();
    }
    catch(Exception e)
    {
    System.out.print("You did something wrong");    
    }
}

public static void ListTasks(FileWriter writer) throws IOException
{
    while(decision.equals("yes"))
    {                   
        System.out.print("Please enter a task: ");
//**************************************************************
        String task = taskInput.nextLine();
//**************************************************************

            // Writes the content to the file
    writer.write(i + " " + task + System.getProperty( "line.separator" ));

        System.out.print("Would you like to enter another task? yes/no: ");
        decision = userContinue.nextLine();
        System.out.print(System.getProperty( "line.separator" ));

        ++i;
    }

    writer.flush();
    writer.close();
}

private static void settings() 
{
    // TODO Auto-generated method stud
    System.out.println("Woah not ready yet");
}

}

0 个答案:

没有答案