Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Default Im writing to a file and i want to skip lines while writing to a text file.

    Im writing to a file and i want to skip lines while writing to a text file.

    heres my class code:



    import java.util.Scanner;
    import java.io.*;
    public class PlayerStats
    {


    public static void FileCreation(String name)
    {


    try
    {
    File create = new File(name);
    create.createNewFile();
    }



    catch(Exception error)
    {
    System.out.print("Error the file couldn't be found or made.");
    }


    }
    public static void Filewriting (String name)
    {
    try
    {

    BufferedWriter out;
    out = new BufferedWriter(new FileWriter(name,true));
    Scanner kboard = new Scanner (System.in);
    String answer01,answer02, answer03, answer04, answer05, answer06, answer07, answer08, answer09, answer10, answer11;
    String answer12, answer13, answer14, answer15, answer16, answer17, answer18, answer19, answer20, answer21, answer22;
    String answer23, answer24, answer25, answer26, answer27, answer28,answer29, answer30, answer31, answer32, answer33;
    String answer34, answer35, answer36;

    FileWriter writer = new FileWriter(name);

    answer10 = ("The date is");
    writer.write(answer10);

    answer11 = (" ");
    writer.write(answer11);

    System.out.println("Type the date is the format of xx/xx/xxxx. ");
    answer01 = kboard.nextLine();
    writer.write(answer01);

    answer28 = (". ");
    writer.write(answer28);

    out.newLine();

    answer12 = ("Name:");
    writer.write(answer12);

    answer13 = (" ");
    writer.write(answer13);

    System.out.println("Type in the players full name.(remember to use _ to seperate first and last) ");
    answer02 = kboard.nextLine();
    writer.write(answer02);

    answer29 = (". ");
    writer.write(answer29);

    answer14 = ("Number of Goals scored is");
    writer.write(answer14);

    answer15 = (" ");
    writer.write(answer15);

    System.out.println("Type in number of goals. ");
    answer03 = kboard.nextLine();
    writer.write(answer03);

    answer30 = (". ");
    writer.write(answer30);

    answer16 = ("Number of assist made is");
    writer.write(answer16);

    answer17 = (" ");
    writer.write(answer17);

    System.out.println("Type in number of assist. ");
    answer04 = kboard.nextLine();
    writer.write(answer04);

    answer31 = (". ");
    writer.write(answer31);

    answer18 = ("Number of Shots on goal is ");
    writer.write(answer18);

    answer19 = (" ");
    writer.write(answer19);

    System.out.println("Type in number of Shoots on goal. ");
    answer05 = kboard.nextLine();
    writer.write(answer05);

    answer32 = (". ");
    writer.write(answer32);

    answer20 = ("Number of faceoff wins made is");
    writer.write(answer20);

    answer21 = (" ");
    writer.write(answer21);

    System.out.println("Type in the number of faceoff wins. ");
    answer06 = kboard.nextLine();
    writer.write(answer06);

    answer33 = (". ");
    writer.write(answer33);

    answer22 = ("Number of faceoff losses made is");
    writer.write(answer22);

    answer23 = (" ");
    writer.write(answer23);

    System.out.println("Type in the number of faceoff losses. ");
    answer07 = kboard.nextLine();
    writer.write(answer07);

    answer34 = (". ");
    writer.write(answer34);

    answer24 = ("Number of fouls made is");
    writer.write(answer24);

    answer25 = (" ");
    writer.write(answer25);

    System.out.println("Type in the number of fouls. ");
    answer08 = kboard.nextLine();
    writer.write(answer08);

    answer35 = (". ");
    writer.write(answer35);

    answer26 = ("Number of tunovers made is");
    writer.write(answer26);

    answer27 = (" ");
    writer.write(answer27);

    System.out.println("Type in the number of turnovers. ");
    answer09 = kboard.nextLine();
    writer.write(answer09);

    answer36 = (". ");
    writer.write(answer36);

    writer.close();
    }


    catch (IOException e)
    {
    System.err.println ("Unable to write to file");
    System.exit(-1);
    }

    }
    public static void fileReading (String name)
    {
    int loop;

    Scanner scan = new Scanner(System.in);
    FileInputStream read;

    try
    {

    read = new FileInputStream (name);

    System.out.println ("This is how your file looks like");
    System.out.println( new DataInputStream(read).readLine() );


    read.close();
    }


    catch (IOException e)
    {
    System.err.println ("Unable to read from file");
    System.exit(-1);
    }



    }







    }

    can you help???

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. writing to text file problem
    By blumdiggity in forum Networking
    Replies: 1
    Last Post: 02-26-2010, 03:43 PM
  2. writing to specific line in text file
    By mickmos in forum New To Java
    Replies: 2
    Last Post: 04-18-2009, 02:01 PM
  3. Writing To A Specific Text File Line
    By mokonji in forum New To Java
    Replies: 1
    Last Post: 03-02-2009, 09:13 PM
  4. [SOLVED] Writing ArrayList to Text File on seperate Lines
    By shinjitsunohana in forum New To Java
    Replies: 9
    Last Post: 08-27-2008, 06:53 PM
  5. writing text to file
    By notwist in forum New To Java
    Replies: 3
    Last Post: 04-25-2008, 05:20 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •