here it is, using this function:
private static void write(String Swrite) throws IOException { if (!StopWordRemoval.exists()) { StopWordRemoval.createNewFile(); } FileOutputStream fop = new FileOutputStream(file); if (Swrite != null) fop.write(Swrite.getBytes()); fop.flush(); fop.close(); } my program gets string from user and write it into a file. after all users done with inputting their info, i want to remove the redundant info. if two exact lines, then one removes. first i tried the below codes but didnt worke out:
private static void Normalize(File file) throws FileNotFoundException, IOException { String tempLine2; BufferedReader buf = new BufferedReader(new FileReader(file)); FileOutputStream fop = new FileOutputStream(temp, true); String tempLine = null; tempLine = buf.readLine(); fop.write(tempLine.getBytes()); BufferedReader buf2 = new BufferedReader(new FileReader(temp)); while ((tempLine = buf.readLine()) != null) { while ((tempLine2 = buf2.readLine()) != null) { if (!tempLine.trim().equals(tempLine2)) { if (tempLine != null) for (final String s : tempLine.split(" ")) { fop.write(s.getBytes()); fop.write(System.getProperty("line.separator").getBytes()); } } } } } my idea in the second function was as below: writing first line into a new file, then comparing second line with it, if different then write, then comparing third line with both...but it seems my function sucks. any help?