hello
can somebody tell me how to write data to array of files ?
thanks
Printable View
hello
can somebody tell me how to write data to array of files ?
thanks
yes I know but let me give you, because I have an error I don't know why
Code:static void Reodering_sub( ){
reodering_output= new File [vector_SA.size()-1];
try {
if (vect_min.size()>1){
vect_ordered_sub.setSize(test_after_filling_ordering.size());
Collections.copy(vect_ordered_sub, test_after_filling_ordering);
Reodering_sub();
test_after_filling_ordering.add(vect_min.get(0).toString());
_2nd_min_element=vect_min.get(0).toString();
vect_ordered_temp.removeElement(next_point);
next_point=_2nd_min_element;
vect_min.remove(vect_min.get(0).toString());
FileWriter writer_rodering_out = new FileWriter(reodering_output[y]);
for (int g = 0; g < vect_ordered_sub.size(); g++) {
writer_rodering_out.write(vect_ordered_sub.get(g).toString());
//writer_rodering_out.write("\r\n\r\n");
}// end for (g) loop
// close wrting into file
writer_rodering_out.close();
}
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
Yes, and why not go all the way and build another wrapper that delegates its own output to all the wrapped outputs; that way you can have a nice reusable component; have a look:
Easy and it fits the IO wrapper framework.Code:// note the plural -s
public class OutputsStream extends OutputStream {
private OutputStream[] outs;
public OutputsStream(OutputStream ... outs) {
this.outs= outs;
}
public void flush() throws IOException {
for (OutputStream out : outs)
out.flush();
}
public void close() throws IOException {
for (OutputStream out : outs)
out.close();
}
public void write(byte[] b) throws IOException {
for (OutputStream out : outs)
out.write(b);
}
public void write(byte[] b,int ofs, int len) throws IOException {
for (OutputStream out : outs)
out.write(b, ofs, len);
}
public void write(int b) throws IOException {
for (OutputStream out : outs)
out.write(b);
}
}
kind regards,
Jos
no but my problem is that I will find vector at each iteration of for loop and then I have to vector into file
this is my code
but there is an error when I run program can you tell me whyCode:
File[]reodering_output ;
reodering_output= new File [vector_v1.size()-1];
for (int y=0; y< vector_v1.size()-1; y++){
v2.setSize(v3.size());
Collections.copy(v2,v3);
v3.add(v5.get(0).toString());
_2nd_min_element=v5.get(0).toString();
v2.removeElement(next_point);
next_point=_2nd_min_element;
v5.remove(v5.get(0).toString());
FileWriter writer_rodering_out = new FileWriter(reodering_output[y]);
for (int g = 0; g < v2.size(); g++) {
writer_rodering_out.write(v2.get(g).toString());
//writer_rodering_out.write("\r\n\r\n");
}// end for (g) loop
// close wrting into file
writer_rodering_out.close();
}}