473,486 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Read file from directory, update contents of the each file

18 New Member
hai,
I could not understand how to debug the error i have now.
target
1- read the files from directory // i able ot do this part
2- for each file
for each file read the content & compare with the existing List & update the list // i able to do this part

when i try to combine both parts , i got some following error

run:
E:\java\check\100130.ixf
Error: children[i] (The system cannot find the file specified)
BUILD SUCCESSFUL (total time: 2 seconds)
i can see from the code that children[i] only gives the error when i use that in the second part of the code.

can any one help me on this??
Thanks
Priyan


the original code
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.DataInputStream;
  5. import java.io.File;
  6. import java.io.FileInputStream;
  7. import java.io.InputStreamReader;
  8. import java.io.RandomAccessFile;
  9. import java.util.ArrayList;
  10.  
  11.  
  12. public class CompareList
  13.     {
  14.  
  15.     public static void main(String[] args){
  16.  
  17.          ArrayList a1 = new ArrayList();
  18.          ArrayList a2 = new ArrayList();
  19.          a1.add("1");
  20.          a1.add("2");
  21.          a1.add("3");
  22.          a1.add("4");
  23.          a1.add("5");
  24.          a1.add("6");
  25.          a1.add("7");
  26.          a1.add("8");
  27.          a1.add("9");
  28.          a1.add("10");
  29.          a1.add("11");
  30.          a1.add("12");
  31.          a1.add("13");
  32.          a1.add("14");
  33.          a1.add("15");
  34.          a1.add("16");
  35.          a1.add("17");
  36.          a1.add("18");
  37.          a1.add("19");
  38.          a1.add("20");
  39.          a1.add("21");
  40.          a1.add("22");
  41.          a1.add("23");
  42.          a1.add("24");
  43.          a1.add("25");
  44.          a1.add("26");
  45.          a1.add("27");
  46.          a1.add("28");
  47.          a1.add("29");
  48.          a1.add("30");
  49.          a1.add("31");
  50.          a1.add("32");
  51.          a1.add("33");
  52.          a1.add("34");
  53.          a1.add("35");
  54.          a1.add("36");
  55.          a1.add("37");
  56.          a1.add("38");
  57.          a1.add("39");
  58.          a1.add("40");
  59.          a1.add("41");
  60.          a1.add("42");
  61.          a1.add("43");
  62.          a1.add("44");
  63.          a1.add("45");
  64.          a1.add("46");
  65.          a1.add("47");
  66.          a1.add("48");
  67.          a1.add("49");
  68.          a1.add("50");
  69.          a1.add("51");
  70.          a1.add("52");
  71.  
  72.           try{
  73.  
  74.                 File dir = new File("E:\\java\\check");
  75.  
  76.                 File[] children = dir.listFiles();
  77.                 if (children == null) {
  78.                       System.out.println("does not exist or is not a directory");
  79.                  }
  80.  
  81.     else {
  82.            for (int i = 0; i < children.length; i++) {
  83.                    System.out.println( children[i]);
  84.                     FileInputStream fstream = new FileInputStream("children[i]");
  85.                     DataInputStream in = new DataInputStream(fstream);
  86.                       BufferedReader br = new BufferedReader(new InputStreamReader(in));
  87.                     String strLine;
  88.                     while ((strLine = br.readLine()) != null)     {
  89.                    String line =strLine.substring(0,2);
  90.                     // Print the content on the console
  91.                      //System.out.println(line);
  92.                      a2.add(line);
  93.                   } // end of add list2
  94.  
  95.            if (a1.size() > a2.size())
  96.          {
  97.              int k = 0;
  98.              for (int l = 0; l < a2.size(); l++)
  99.              {
  100.                  if (!((String)a1.get(l)).equals((String)a2.get(l)))
  101.                  {
  102.                      //System.out.println((String)a2.get(i));
  103.                       // System.out.println("dd");
  104.                  }
  105.                  k = l;
  106.              }
  107.              k++;
  108.              for (int l = k; l < a1.size(); l++)
  109.              {
  110.                  System.out.println((String)a1.get(l));
  111.                 String str = "children[l]";
  112.  
  113.                 File file = new File(str);
  114.                  RandomAccessFile rand = new RandomAccessFile(file,"rw");
  115.  
  116.                   rand.seek(file.length());  //Seek to end of file
  117.                   rand.writeBytes((String)a1.get(i));  //Write end of file
  118.                   rand.writeBytes("., 0.");
  119.                   rand.writeBytes("\n");
  120.  
  121.  
  122.              }
  123.          }// end of comparing and updating the list2
  124.  
  125.         in.close();
  126.         }
  127.     }
  128.      }
  129.               catch (Exception e){//Catch exception if any
  130.                 System.err.println("Error: " + e.getMessage());
  131.         }
  132.     }
  133. }
  134.  
  135.  
May 11 '09 #1
0 3149

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1675
by: Angelos | last post by:
Hello.. I am trying to make a filesystem management script. I want to display a list of files and directories and be able to delete them from this list.... I made a search on the net and there are...
1
3909
by: Gema Gema | last post by:
I have a large collection of directories full of various files and am looking to create custom text files for the contents of each directory. Here is the situation: The directories are named...
1
3931
by: Fie Fie Niles | last post by:
I have IIS installed on XP Professional workstation machine. I have an ASP page that open connection to an Access database, then when trying to update the database, it gave me the error "cannot...
5
7515
by: JenHu | last post by:
Hi experts, I wrote a function which retrieves a file in the folder, the file path is : Dim sr As New StreamReader(strFilepath & ReturnFileName) What if I have more than 1 file_name in...
4
5875
by: Jim Michaels | last post by:
after a file upload, $_FILES is not populated but $_POST is. what's going on here? $_POST=C $_POST=C $_POST=C $_POST=C:\\www\\jimm\\images\\bg1.jpg $_FILES= $_FILES= $_FILES=
1
1365
by: Psapg | last post by:
Hi! I'm new to javasript, and i must confess to have borowed a few free scripts from the net to satisfie my needs.... Still i can't find even an idea of ascipt to do this... Please Help!!! ...
21
7792
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
6
2905
ak1dnar
by: ak1dnar | last post by:
Hi, I have created Sub in VB.net application, Which reads a text file contents. Sub IPsetter() Dim fileName As String Dim realIParray As String() = Nothing Dim...
4
11007
by: Mr Gray | last post by:
Hi Guys, My requirement is to scan an FTP directory for the presence of 4 files and if a specific file exists I can begin to GET those files, read the contents and save the contents into an SQL...
0
7105
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7180
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.