/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package p1;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class add_csv {
public static void main(String[] args) {
File f1= new File("E://data4.txt");
BufferedReader br,br2;
int size=0;
try {
br = new BufferedReader(new FileReader(f1));
String line;
int sum=0;
while((line=br.readLine())!=null){
StringTokenizer st= new StringTokenizer(line,",");
while(st.hasMoreTokens()){
String p=st.nextToken();
//sum+=Integer.parseInt(p);
System.out.println(p);
size++;
}
}
br.close();
br2 = new BufferedReader(new FileReader("E://data4.txt"));
FileOutputStream os= new FileOutputStream("E://copy4.txt");
String[] myst= new String[size];
int i=0;
while((line=br2.readLine())!=null){
StringTokenizer st= new StringTokenizer(line,",");
while(st.hasMoreTokens()){
String p=st.nextToken();
myst[i++]=p;
//System.out.println(i);
}
}
System.out.println(" ");
for(int k=0;k<size;k++){
for(int j=k+1;j<size;j++){
if(myst[k].compareTo(myst[j])>0){
String temp=myst[k];
// System.out.println("hi");
myst[k]=myst[j];
myst[j]=temp;
}
}
}
for(String pintu:myst){
System.out.println(pintu);
os.write(pintu.getBytes());
os.write(" \n".getBytes());
}
System.out.println("The sum of integer is "+sum);
} catch (Exception ex) {
Logger.getLogger(add_csv.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package p1;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class add_csv {
public static void main(String[] args) {
File f1= new File("E://data4.txt");
BufferedReader br,br2;
int size=0;
try {
br = new BufferedReader(new FileReader(f1));
String line;
int sum=0;
while((line=br.readLine())!=null){
StringTokenizer st= new StringTokenizer(line,",");
while(st.hasMoreTokens()){
String p=st.nextToken();
//sum+=Integer.parseInt(p);
System.out.println(p);
size++;
}
}
br.close();
br2 = new BufferedReader(new FileReader("E://data4.txt"));
FileOutputStream os= new FileOutputStream("E://copy4.txt");
String[] myst= new String[size];
int i=0;
while((line=br2.readLine())!=null){
StringTokenizer st= new StringTokenizer(line,",");
while(st.hasMoreTokens()){
String p=st.nextToken();
myst[i++]=p;
//System.out.println(i);
}
}
System.out.println(" ");
for(int k=0;k<size;k++){
for(int j=k+1;j<size;j++){
if(myst[k].compareTo(myst[j])>0){
String temp=myst[k];
// System.out.println("hi");
myst[k]=myst[j];
myst[j]=temp;
}
}
}
for(String pintu:myst){
System.out.println(pintu);
os.write(pintu.getBytes());
os.write(" \n".getBytes());
}
System.out.println("The sum of integer is "+sum);
} catch (Exception ex) {
Logger.getLogger(add_csv.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
No comments:
Post a Comment