Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2011
    Posts
    24
    Rep Power
    0

    Default Creating files using loops

    Hi.. can some one give a code for creating files using loops and to write data in to that file....

  2. #2
    Join Date
    Jun 2011
    Posts
    24
    Rep Power
    0

    Default

    Here is the code which I have tried....can someone help me in this.....

    public class Main
    {
    public static void main(String[] args) throws FileNotFoundException
    {
    BufferedReader obj1 = new BufferedReader(new FileReader("D://sampleinput.txt"));
    String dest = ("D://Enhancer_Chr_Wise//");
    String s2;
    String[] s1=new String[8];
    while((s2=obj1.readLine())!=null)
    {
    s1 = s2.split("\t");
    String chr_no = s1[7];
    File f = new File(dest + chr_no + ".txt");
    f.write(s1[0] + s1[2] + s1[3] + s1[4] + s1[5] + s1[6]);
    }

    }

    }

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    Have you looked at the API doc to see what class to use for writing the file?
    The classes often come in pairs, there will be a writer for every reader or output for every input class.
    For example you are using BufferedReader, see if there is a BufferedWriter

    Does the File class have a write() method? What does the API doc say?

Similar Threads

  1. Creating Jar Files with functioning input files
    By appleLove in forum NetBeans
    Replies: 1
    Last Post: 04-10-2011, 11:37 PM
  2. HELP - Creating OPTIONS in program and LOOPS
    By whateverme in forum New To Java
    Replies: 14
    Last Post: 12-07-2010, 06:55 AM
  3. Creating files stopped creating...
    By Dieter in forum Advanced Java
    Replies: 3
    Last Post: 09-26-2009, 12:45 AM
  4. Replies: 2
    Last Post: 02-23-2009, 03:18 AM
  5. Creating .Jar files
    By Deathmonger in forum New To Java
    Replies: 6
    Last Post: 06-23-2008, 12:59 AM

Posting Permissions

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