Originally posted by shana07
[CODE=java]if(a.equals(b)) {
// ...
}[/CODE]
while((lineFRST != null) && (lineSEC != null))
{
printWriter = new PrintWriter( new FileWriter("OutputFile.txt", true));
String[] thelineFRST = lineFRST.split(" ");
String fileNo1 = thelineFRST[0];
String[] thelineSEC = lineSEC.split(" ");
String fileNo2 = thelineSEC[0];
if(fileNo1.equals(fileNo2))
{
printWriter.println(lineFRST);
}
else
{
printWriter.println(lineFRST);
printWriter.println(lineSEC);
}
printWriter.close();
lineFRST = in1.readLine();
lineSEC = in1.readLine();
}
in1.close();
while((lineFRST != null) && (lineSEC != null))
{
printWriter = new PrintWriter( new FileWriter("OutputFile.txt", true));
String[] thelineFRST = lineFRST.split(" ");
String fileNo1 = thelineFRST[0];
String[] thelineSEC = lineSEC.split(" ");
String fileNo2 = thelineSEC[0];
if(fileNo1.equals(fileNo2))
{
printWriter.println(lineFRST);
}
else
{
printWriter.println(lineFRST);
printWriter.println(lineSEC);
}
printWriter.close();
lineFRST = in1.readLine();
lineSEC = in1.readLine();
}
in1.close();
public class FinalSort
{
private static void analyseLines(String[] lines, int m)
{
PrintWriter printWriter = null;
BufferedWriter bufferWriter = null;
printWriter = new PrintWriter(new BufferedWriter(new FileWriter("C:\\result\\" + m +"Final.txt", true))); //To get back 40 output files: eg: 1Final.txt
for (int i=0; i < lines.length-1; i+=2) {
String pos = lines[0];
String[] current = pos[i]; //array required but string found
String[] next = pos[i+1]; //array required but string found
if(current.equals(next)) {
printWriter.println (lines[i]); }
else {
printWriter.println (lines[i]);
printWriter.println (lines[i+1]);
}
}
}
private static String[] readLines (String fileName) throws IOException
{
List lines = new ArrayList();
while (fileName != null)
{
lines.add (fileName);
}
return lines; //How to return 'lines' as an array of Strings?
}
public static void main(String[] args) throws IOException
{
for (int m=1; m<=40; m++) // there are 40 files need to be analysed - eg: 1ResultFile.txt
{
String[] lines = readLines (m + "ResultFile.txt");
analyseLines (lines, m);
}
}
}
...
private static String[] readLines (String fileName) throws IOException
{
List lines = new ArrayList();
while (fileName != null)
{
lines.add (fileName);
}
...
...
return lines; //How to return 'lines' as an array of Strings?
}
private static String[] readLines (String fileName, int m) throws IOException
{
List lines = new ArrayList();
String lineFRST = "";
String lineSEC = "";
BufferedReader in1 = new BufferedReader (new FileReader( m + "FileInput.txt"));
lineFRST = in1.readLine();
lineSEC = in1.readLine();
while (fileName != null)
{
lines.add (lineFRST);
lines.add(lineSEC);
}
return toArray (lines); //is this correct?
}
private static String[] readLines (String fileName, int m) throws IOException
{
List lines = new ArrayList();
String lineFRST = "";
String lineSEC = "";
BufferedReader in1 = new BufferedReader (new FileReader( m + "FileInput.txt"));
lineFRST = in1.readLine();
lineSEC = in1.readLine();
while (fileName != null)
{
lines.add (lineFRST);
lines.add(lineSEC);
}
...
}
private static String[] readLines (String fileName, int m) throws IOException
{
List lines = new ArrayList();
String lineFRST = "";
String lineSEC = "";
BufferedReader in1 = new BufferedReader (new FileReader( m + "FileInput.txt"));
lineFRST = in1.readLine(); //Okay?
while (fileName != null)
{
lines.add (lineFRST);
}
return (String[]) lines.toArray(); //Okay?
}
private static String[] readLines (String fileName, int m) throws IOException
{
List lines = new ArrayList();
String lineFRST = "";
String lineSEC = "";
BufferedReader in1 = new BufferedReader (new FileReader( m + "FileInput.txt"));
lineFRST = in1.readLine(); //Okay?
while (fileName != null)
{
lines.add (lineFRST);
}
return (String[]) lines.toArray(); //Okay?
}
Comment