Results 1 to 5 of 5

Thread: array of iles

  1. #1
    sara12345 is offline Member
    Join Date
    Dec 2009
    Posts
    59
    Rep Power
    0

    Default array of iles

    hello
    can somebody tell me how to write data to array of files ?
    thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by sara12345 View Post
    hello
    can somebody tell me how to write data to array of files ?
    thanks
    You can do this with a for loop.

  3. #3
    sara12345 is offline Member
    Join Date
    Dec 2009
    Posts
    59
    Rep Power
    0

    Default

    yes I know but let me give you, because I have an error I don't know why
    Java 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();
    		   }          			
    }

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,656
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Fubarable View Post
    You can do this with a for loop.
    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:

    Java 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);
    	}
    }
    Easy and it fits the IO wrapper framework.

    kind regards,

    Jos

  5. #5
    sara12345 is offline Member
    Join Date
    Dec 2009
    Posts
    59
    Rep Power
    0

    Default

    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
    Java Code:
     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();
    	         			
    	         	   }}
    but there is an error when I run program can you tell me why

Similar Threads

  1. convert byte array into char array
    By kgkamaraj in forum New To Java
    Replies: 4
    Last Post: 09-13-2011, 11:32 AM
  2. Convert Char Array to String Array
    By Mayur in forum New To Java
    Replies: 8
    Last Post: 10-12-2009, 11:41 AM
  3. Array length and printing out uninitialized array.
    By nicolek808 in forum New To Java
    Replies: 4
    Last Post: 09-10-2009, 09:12 AM
  4. How to transfer 1D array in JAVA to 3D array in C
    By fishwater00 in forum New To Java
    Replies: 0
    Last Post: 07-31-2009, 06:24 PM
  5. Replies: 1
    Last Post: 03-31-2009, 06:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •