how to write them into separate text files using java


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: how to write them into separate text files using java

  1. #1
    Join Date
    Nov 2005
    Posts
    37

    how to write them into separate text files using java

    I have a text file having the following content:

    ......
    end
    ............
    ...........
    ...................
    end
    ............................
    .........
    end

    What I'm trying to do is to divide the content of the file into several pieces just by the keyword "end", and then write each piece into a separate text file. Could anybody teach me how to implement this. Thank you very much!

  2. #2
    Join Date
    Dec 2005
    Location
    New Jersey
    Posts
    290
    What have you tried so far?

  3. #3
    Join Date
    Mar 2005
    Location
    UK, London
    Posts
    150
    Read the file line by line using a loop. Store each line to an array or an arraylist, have an if statment that checks if the current line contains the word "end" strLine.equals("end"), if it does then save the new file, and create a new file and continue with the loop until you reach the end of the loop. Does that make any sense.

  4. #4
    Join Date
    Mar 2005
    Location
    UK, London
    Posts
    150

    mysql, communication link failure

    Hi guys hope some one can help. Im trying to connect my java app with mysql database which is running on a remote server meaning a web hosting account. I recieve the following message communication link failure. Has any one faced this problem before. I thoug maybe that that hosting compnay may not allow remote connections due to security reasons. So i installed mysql on my networked and tried to accessed it within my network but i get the same message. Any ways to where Im going wrong?

  5. #5
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    use Scanner class - with "end" as the delimiter. Write each of the tokens to a file, in turn.

  6. #6
    Join Date
    Mar 2005
    Location
    UK, London
    Posts
    150
    ohhhh, thats where my thread went. I though I made a new thread for my java question, seems like I didnt make a new thread after all. Sorry guys must have clicked the wrong button. You can use the split function too. If im correct the split function is ment to replace the token

  7. #7
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Yes - as the API documentation says for StringTokenizer:

    StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.

    Take a look at the Scanner class - it is VERY useful for all streams and for Strings, with great flexibility in delimiters and the handling of primitive datatypes.

Similar Threads

  1. Replies: 0
    Last Post: 12-20-2005, 05:29 AM
  2. Read Large Text Files
    By Hutty in forum ASP.NET
    Replies: 0
    Last Post: 09-27-2005, 04:11 PM
  3. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  4. Replies: 0
    Last Post: 04-07-2005, 01:31 PM
  5. Getting a GUI to function
    By Eric in forum Java
    Replies: 1
    Last Post: 11-27-2001, 06:53 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center