473,800 Members | 3,029 Online
Bytes | Software Development & Data Engineering Community
+ 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\1 00130.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 3168

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

Similar topics

4
1696
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 loads of them but I am trying to do something much more simple. At the moment I can display everything within a folder but if I click on a directory it won't go into the directory, listing all contents ... it is just a link.
1
3931
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 with a name and number, i.e. Smith1234567. I am looking to create a text file named with the number portion of the directory name (1234567.txt). The contents of the text file would look similar to the following, where the "TIF" files at the end of...
1
3965
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 update database or object is read-only". This is a workstation machine, not connected to any other computer, and I login to the PC using an administrator account. I already check the .MDB file is NOT read-only. But, I do not see the .LDB file....
5
7541
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 EPay_Batch_Table Where File_Status=2? How to read multiple files and 1 file at a time, through a loop?
4
5901
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
1380
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!!! I have a webserver setup in my home, with an index file that is an access comtrol page, that, if the authentication is sucessfull, takes the user to a
21
7866
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
2941
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 ipString As String
4
11107
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 2005 DB. The files are of a fixed length format which map to certain elements of data that my database will exploit. If i can learn to read 1 file and put the contents into the DB then I can do the other 3 on my own. So far I can connect to the...
0
9694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9553
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10509
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10281
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10256
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10039
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6824
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4152
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 we have to send another system
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.