Results 1 to 19 of 19
  1. #1
    mazu is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default how to remove constraint from output file

    please help me on these problem. I have 2 files, one named output.txt and one named constraint.txt. I need to compare the contents of those files line by line....(contents are array like this: a1,b2,c2,
    a2,b1,c1,
    a2,b1,c2, )

    if any constraint exist in output file, i have to delete the line and will produce final output file without constraint...

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    What have you done so far?

  3. #3
    mazu is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    not much, i am new , can i use scanner class?

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You could yes. Or a FileReader BufferedReader combination.

  5. #5
    mazu is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    sir, can you give some code example?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  7. #7
    mazu is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    can somebody help me to give sample code??I really dont have an idea how to start...

  8. #8
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Start by reading the API specs for BufferedReader.
    You need to show that you tried to write the code before you can get anyone posting code for you.

  9. #9
    jpavan is offline Member
    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0

    Default Class def not found exception

    Iam using Jasper reports jar files to open reports from application.After deploying the war file of application in tomcat 6, iam unable to open reports and it is showing class def not found exception.If i manually set the class path of these jasper reports jar files in tomcat, i was able to open the reports.
    Is there any solution to resolve this problem of manually setting the class path of report jar file in tomcat when ever i deploy a new war file?

  10. #10
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Either include the jar in tomcat's lib or in your application's WEB-INF/lib folder.

    P.S Why post this in someone's thread? Why not start your own thread?

  11. #11
    mazu is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    this is my code,

    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.BufferedReader;
    import java.io.PrintWriter;
    import java.io.IOException;

    public class compare {
    public static void main(String[] args) throws IOException

    //read two files


    BufferedReader br = new BufferedReader(new FileReader("E:\\constraint.txt"));
    BufferedReader br1 = new BufferedReader(new FileReader("E:\\File1.txt"));

    line = br.readLine();
    line = br1.readLine();

    //create output file

    Writer output = null;
    output = new BufferedWriter(new FileWriter("mazu.txt"));
    String newline = System.getProperty("line.separator")

    //compare the content of 2 files, if constraint exist in File1, delete the line and write the output on mazu.txt.

    -----up to this part i have no idea---

  12. #12
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Write down an algorithm of how you would do it "manually", then transform those steps into a Java program. You now have all the Java tools you need to complete this. All you need is the logic.

  13. #13
    mazu is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    import java.io.BufferedReader;
    import java.io.FileReader;
    public class compares {
    public static void main(String[] argv)
    throws Exception{
    BufferedReader fh =
    new BufferedReader(new FileReader("File1.txt"));
    BufferedReader sh =
    new BufferedReader(new FileReader("File2.txt"));
    String s;
    String y;
    while ((s=fh.readLine())!=null)
    if ( s.equals(y=sh.readLine()) )
    {
    System.out.println("constraint");
    }
    else {
    System.out.println("final output");
    }
    sh.close();
    fh.close(); }
    }[/I]

    i have done this but it just compare line by line..ie

    line1 of file1 with line1 of file2
    line2 of file1 with line2 of file2
    line3 of file1 with line3 of file2

    But I want it compares all lines..for example like this:-

    line1 of file1 with line1 of file2
    line1 of file1 with line2 of file2..
    line1 of file1 with line3 of file2...

    then,

    line2 of file1 with line1 of file2
    line2 of file1 with line2 of file2
    line2 of file1 with line3 of file2..

    and so on...

    I think it may have a looping to do that, but how? could somebody help me?

  14. #14
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    So you need two while loops, right?

  15. #15
    mazu is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    while ((s=fh.readLine())!=null)

    {
    while ((y=sh.readLine())!=null)


    if (s.equals(y))

    {
    System.out.println("constraint");
    }
    else
    {
    System.out.println("final output");
    }

    }


    When i try run this, only inner while loop executed for this code, after that it did not go to outer loop....

  16. #16
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    Second while completley executes till the end of file as per ur logic

    My question here is if the no of lines of files are same.u maintain only one loop for the master file and do the comparison.
    Ramya:cool:

  17. #17
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by mazu View Post
    ...

    When i try run this, only inner while loop executed for this code, after that it did not go to outer loop....
    Because you has reached the end of the second file.
    Consider loading the second file into a List<String> and working with that list.

  18. #18
    mazu is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    please give me an example on how to do with List<String>

  19. #19
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Just create a List<String> and read the file adding each line to the List. No need for me to write the code.

Similar Threads

  1. remove variables/line in a text file
    By ddatta8 in forum New To Java
    Replies: 2
    Last Post: 01-04-2009, 03:05 AM
  2. How to remove 2 last lines in a text file?
    By Marius in forum New To Java
    Replies: 2
    Last Post: 11-30-2008, 03:54 PM
  3. Remove control characters in txt file
    By trivektor in forum New To Java
    Replies: 7
    Last Post: 09-23-2008, 04:22 PM
  4. remove a portion from a file
    By alon2580 in forum New To Java
    Replies: 13
    Last Post: 08-25-2008, 01:45 PM
  5. [SOLVED] Remove All Line from File
    By Mir in forum New To Java
    Replies: 41
    Last Post: 07-17-2008, 09:44 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
  •