Java public class Sort1
              in 
             Programming Questions 
              •  
              2 years ago    
            
 
           
             I copied a Java public class Sort1 and am trying to put it in a Processing program.
            
 
            
             I'm not sure what to do with the main() method.
            
 
            
             Here is what I have for now, but it's not working. Even Auto Format is not working.
            
 
            - import java.io.*; import java.util.*;
 - void setup() {
size(120,120);
noLoop();
} - draw() {
} - public class Sort1 {
String infile;
String outfile; - Sort1(String infile_, String outfile_) {
//infile="fileToRead.txt"
//outfile="fileToWrite.txt"
infile=infile_;
outfile=outfile_;
} - void sortfile() throws Exception {     
BufferedReader reader = new BufferedReader(new FileReader(infile));
Map<String, String> map=new TreeMap<String, String>();
String line="";
while((line=reader.readLine())!=null){
map.put(getField(line),line);
}
reader.close();
BufferedWriter writer = new BufferedWriter(new FileWriter(outfile));
for(String val : map.values()) {
writer.write(val);
writer.newLine();
}
writer.close();
}//sortfile()
private static String getField(String line) {
return line.split(" ")[0];//extract value you want to sort on
}//getField()
}
 
 
              
              1  
            
 
            