Click here to Skip to main content
15,868,128 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
problem is like that when i read file and i perform some operation on that and write that file but when i read 50 page when i write again i got only 47 page please suggest what can i do. my code bellow.
Java
public class DataSeperation {
    public static void main(String[] args) throws IOException {
        BufferedReader rd=new BufferedReader(new FileReader("D:\\Data.txt"));
        File tempFile = new File("myTempFile.txt");
        BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
        String lineToRemove = "208 vaDgaava SaorI ivaQaanasaBaa matadar saMGa : dubaar matadar yaadI Ah-taa idnaaMkx : 1ó1ó2013 va pa`isawI idnaaMkx : 1ó10ó2012";
        
        String currentLine;
        
        while((currentLine =rd.readLine()) != null) {
            // trim newline when comparing with lineToRemove
            String trimmedLine = currentLine.trim();
            if(trimmedLine.equals(lineToRemove)) continue;
            writer.write(System.getProperty("line.separator"));
            writer.write(currentLine);
        }
        
    
    }
    
}
Posted
Updated 6-Feb-14 6:36am
v2

1 solution

In your code, you are skipping some time from read data, so what do you want? Run it under the debugger and see if you are skipping something you want to keep. :-)

—SA
 
Share this answer
 
Comments
baliram bhande 7-Feb-14 2:53am    
i want to skip some data that are present in lineToremove variable .my main theme is i want to remove some lines from the file and else part of the file can be write as same.in above cod line can be remove what i want but problem is that what else file can not write hole .there may be loss some pages.
Sergey Alexandrovich Kryukov 7-Feb-14 10:45am    
You the debugger, and you will know something we both don't know. Why speculating having not enough information?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900