Read file from directory, update contents of the each file
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
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.util.ArrayList;
public class CompareList
public static void main(String[] args){
ArrayList a1 = new ArrayList();
ArrayList a2 = new ArrayList();
a1.add("1");
a1.add("2");
a1.add("3");
a1.add("4");
a1.add("5");
a1.add("6");
a1.add("7");
a1.add("8");
a1.add("9");
a1.add("10");
a1.add("11");
a1.add("12");
a1.add("13");
a1.add("14");
a1.add("15");
a1.add("16");
a1.add("17");
a1.add("18");
a1.add("19");
a1.add("20");
a1.add("21");
a1.add("22");
a1.add("23");
a1.add("24");
a1.add("25");
a1.add("26");
a1.add("27");
a1.add("28");
a1.add("29");
a1.add("30");
a1.add("31");
a1.add("32");
a1.add("33");
a1.add("34");
a1.add("35");
a1.add("36");
a1.add("37");
a1.add("38");
a1.add("39");
a1.add("40");
a1.add("41");
a1.add("42");
a1.add("43");
a1.add("44");
a1.add("45");
a1.add("46");
a1.add("47");
a1.add("48");
a1.add("49");
a1.add("50");
a1.add("51");
a1.add("52");
try{
File dir = new File("E:\\java\\check");
File[] children = dir.listFiles();
if (children == null) {
System.out.println("does not exist or is not a directory");
else {
for (int i = 0; i < children.length; i++) {
System.out.println( children);
FileInputStream fstream = new FileInputStream("children[i]");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
String line =strLine.substring(0,2);
// Print the content on the console
//System.out.println(line);
a2.add(line);
} // end of add list2
if (a1.size() > a2.size())
int k = 0;
for (int l = 0; l < a2.size(); l++)
if (!((String)a1.get(l)).equals((String)a2.get(l)))
//System.out.println((String)a2.get(i));
// System.out.println("dd");
k = l;
k++;
for (int l = k; l < a1.size(); l++)
System.out.println((String)a1.get(l));
String str = "children[l]";
File file = new File(str);
RandomAccessFile rand = new RandomAccessFile(file,"rw");
rand.seek(file.length()); //Seek to end of file
rand.writeBytes((String)a1.get(i)); //Write end of file
rand.writeBytes("., 0.");
rand.writeBytes("\n");
}// end of comparing and updating the list2
in.close();
catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
thanks for the information.
i tried, the error
like this
run:
E:\java\check\100130.ixf
java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at java.lang.String.substring(String.java:1935)
at CompareList.main(CompareList.java:84)
BUILD SUCCESSFUL (total time: 0 seconds)this comes because in my code i used children[i] as string in the later part
else {
for (int i = 0; i < children.length; i++) {
System.out.println( children);
FileInputStream fstream = new FileInputStream(children[i]);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
String line =strLine.substring(0,2);
a2.add(line);
System.out.println(line);
} // end of add list2
if (a1.size() > a2.size())
int k = 0;
for (int l = 0; l < a2.size(); l++)
if (!((String)a1.get(l)).equals((String)a2.get(l)))
//System.out.println((String)a2.get(i));
// System.out.println("dd");
k = l;
k++;
for (int l = k; l < a1.size(); l++)
System.out.println((String)a1.get(l));
String str = "children[l]";
File file = new File(str);
RandomAccessFile rand = new RandomAccessFile(file,"rw");
rand.seek(file.length()); //Seek to end of file
rand.writeBytes((String)a1.get(i)); //Write end of file
rand.writeBytes("., 0.");
rand.writeBytes("\n");
rand.close();
}// end of comparing and updating the list2
in.close();
i stil could not figure out it yet. do u have any clue with this.
Similar Messages
-
I have different music files in three computers.
Everytime I connect my iPod into one of these computers it transfer the music files from that computer but delete the music files that I already have in my iPod.
I want all my music in my iPod.
What I need to do?
Thanks!I haven't researched it and I don't claim to know everything about iTunes, but it has always been my understanding that you can only use one computer per iPod, but you can have multiple iPods per computer. From what I understand, this is to prevent illegal sharing and whatnot.
-
How do I move data files for mSecure (a password saver app) from old iPhone 3GS to new iPhone 4S?
That article is about using your iPod as an external hard drive, to move files from one computer to another computer. It is not related to your question.
You can't use iTunes to move song files from iPod to computer, except for songs you purchased from the iTunes Store (and you can also re-download purchases). However, there are third-party methods and utilities that can move song files from iPod to computer. If you do a Google search on something like "ipod transfer," you should get some links.
Once the song files are on your current computer, add them to that computer's iTunes library by dragging the files (or folder containing the files) to the iTunes window. After confirming everything is there (and fixing the data issue you mentioned) you can sync the iPod. You may want to do a Restore on the iPod, if it might have a data corruption issue, which will erase the iPod's hard drive, re-install the latest software, and set it to defautl settings. -
How to call a jsp file from an servlet and access the jsp file objects??
Hi everybody
I have an jsp file where it contains a vector object with some data and I have a servlet that needs to access this vector object . How can my servlet call for this jsp page and get the vector object. ?
then an applet will be calling this servlet to get some other object created with the data contained within this vector object...so each time Applet ask the servlet for the object the servlet need to call for this jsp page somehow
My main question is the communication servlet-jsp
please if u have any clue I will appreciate it
thanksHi
There are several ways to share objects between JSPs/Servlets.
You can share objects by putting them in the request-in which case the objects lifetime is limited by that of the request, Another way is to store them in the session, againg the lifetime is limited by the lifetime of the session. To have objects that have to persistent over the application life-span use the servletContext to store the objects.
Any good tutorial should help you get started. Please see the link below for a tutorial on Servlets/JSPs
Note: Local variables in the JSP cannot be shared with other components as their scope is limited to that particular Page/Servlet.
Link: http://java.sun.com/docs/books/tutorial/servlets/
Good Luck!
Eshwar Rao
Developer Technical Support
Sun microsystems inc
http://www.sun.com/developers/support -
Can't deleted files from hdd despites itunes managing the library
Hey,
I ran into a little problem today. I am rather new mac user and absolutely loving it. My itunes is setup with the library in the Shared folder with all the same access rights, which allows me to have the same library for both users on the computer. The folder is Computer:User:Shared:Music:iTunes Music:
But when I try to delete an album in itunes, it doesn't delete it from the actal hdd. I got both options in the settings checked, ie manages the itunes library and copies the files to itunes folder when added.
Any idea how I could get around this and fix this?
//Jacob"And you are telling me that all the songs have to be within the itunes folder right?"
You can put your song files anywhere you want. All I have said is that when you delete a song from an iTunes library, iTunes will only give you the option of erasing the file from your hard drive if the song file is in the folder designated by "iTunes Music folder location."
"How come when I import an album, that it is placed in the Musik folder rather than Musik:itunes folder?"
Based on the example you gave, where the iTunes Music folder location is set as Users:Shared:Musik:iTunes Music, this is impossible. New albums would go in the iTunes Music folder, not the parent Musik folder. Check your setting and try importing another album. If what you say is true, it is an anomaly that cannot be explained. -
Size & content of the compiled file from Forms Builder (Oracle Developer 6)
Hi all.
Two files resulted from the compilation of the same form are different according to byte-to-byte comparison (security requirements of the customer). What could be the reason of this? Any suggestions?
Thanks in advance.
Igor.I doubt you will find any documentation about the content or size.
I take it you are curious about the size and content in the .fmx file, but there is an even more dramatic difference in size of the .fmb file depending on how it is saved.
You can read up on it here:
Re: FMB size shrinks dramatically
and
Re: Why does this happen - find ';', replace with ';'?
You can see the .fmx size balloon if you compile the fmb after doing a semicolon - semicolon replace, IF you don't first save, close, then re-open the fmb file.
In fact, if you are seeing the fmx size change, it may be related to that problem with the fmb. Here at our site, developers ALWAYS do the semicolon - semicolon replace and save and close without compiling with EVERY form they work on. It guarantees that when the fmb is compiled at the users sites, they get a clean fmx.
You might, in fact, try comparing two fmx files generated from a "clean" fmb, and see if the two compare the same or different. ( Please let me know! ) -
HOW TO READ MULTIPLE FILES FROM DIRECTORY
i have a directory with 100 .sql insert scripts.i want to read all .sql files from directory and execute the insert script automatically.
Let's suppose you have 3 files: "first.sql", "second.sql" and "third.sql". Create a file named "all.sql" in the same directory, containing this:
@@first.sql
@@second.sql
@@third.sqlRun "all.sql". -
How to delete a READ ONLY file from Directory
Hi Friends,
how to delete a READ ONLY file from Directory , file is in my system only.
Please help me .
note: its read only file.
Thank you.
Karthik.hI,
try with this statement.
delete dataset <datasetname>.
this will definitely work.
Regards,
Nagaraj -
How to write the JTables Content into the CSV File.
Hi Friends
I managed to write the Database records into the CSV Files. Now i would like to add the JTables contend into the CSV Files.
I just add the Code which Used to write the Database records into the CSV Files.
void exportApi()throws Exception
try
PrintWriter writing= new PrintWriter(new FileWriter("Report.csv"));
System.out.println("Connected");
stexport=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
rsexport=stexport.executeQuery("Select * from IssuedBook ");
ResultSetMetaData md = rsexport.getMetaData();
int columns = md.getColumnCount();
String fieldNames[]={"No","Name","Author","Date","Id","Issued","Return"};
//write fields names
String rec = "";
for (int i=0; i < fieldNames.length; i++)
rec +='\"'+fieldNames[i]+'\"';
rec+=",";
if (rec.endsWith(",")) rec=rec.substring(0, (rec.length()-1));
writing.println(rec);
//write values from result set to file
rsexport.beforeFirst();
while(rsexport.next())
rec = "";
for (int i=1; i < (columns+1); i++)
try
rec +="\""+rsexport.getString(i)+"\",";
rec +="\""+rsexport.getInt(i)+"\",";
catch(SQLException sqle)
// I would add this System.out.println("Exception in retrieval in for loop:\n"+sqle);
if (rec.endsWith(",")) rec=rec.substring(0,(rec.length()-1));
writing.println(rec);
writing.close();
}With this Same code how to Write the JTable content into the CSV Files.
Please tell me how to implement this.
Thank you for your Service
JofinHi Friends
I just modified my code and tried according to your suggestion. But here it does not print the records inside CSV File. But when i use ResultSet it prints the Records inside the CSV. Now i want to Display only the JTable content.
I am posting my code here. Please run this code and find the Report.csv file in your current Directory. and please help me to come out of this Problem.
import javax.swing.*;
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;
public class Exporting extends JDialog implements ActionListener
private JRadioButton rby,rbn,rbr,rbnore,rbnorest;
private ButtonGroup bg;
private JPanel exportpanel;
private JButton btnExpots;
FileReader reading=null;
FileWriter writing=null;
JTable table;
JScrollPane scroll;
public Exporting()throws Exception
setSize(550,450);
setTitle("Export Results");
this.setLocation(100,100);
String Heading[]={"BOOK ID","NAME","AUTHOR","PRICE"};
String records[][]={{"B0201","JAVA PROGRAMING","JAMES","1234.00"},
{"B0202","SERVLET PROGRAMING","GOSLIN","1425.00"},
{"B0203","PHP DEVELOPMENT","SUNITHA","123"},
{"B0204","PRIAM","SELVI","1354"},
{"B0205","JAVA PROGRAMING","JAMES","1234.00"},
{"B0206","SERVLET PROGRAMING","GOSLIN","1425.00"},
{"B0207","PHP DEVELOPMENT","SUNITHA","123"},
{"B0208","PRIAM","SELVI","1354"}};
btnExpots= new JButton("Export");
btnExpots.addActionListener(this);
btnExpots.setBounds(140,200,60,25);
table = new JTable();
scroll=new JScrollPane(table);
((DefaultTableModel)table.getModel()).setDataVector(records,Heading);
System.out.println(table.getModel());
exportpanel= new JPanel();
exportpanel.add(btnExpots,BorderLayout.SOUTH);
exportpanel.add(scroll);
getContentPane().add(exportpanel);
setVisible(true);
public void actionPerformed(ActionEvent ae)
Object obj=ae.getSource();
try {
PrintWriter writing= new PrintWriter(new FileWriter("Report.csv"));
if(obj==btnExpots)
for(int row=0;row<table.getRowCount();++row)
for(int col=0;col<table.getColumnCount();++col)
Object ob=table.getValueAt(row,col);
//exportApi(ob);
System.out.println(ob);
System.out.println("Connected");
String fieldNames[]={"BOOK ID","NAME","AUTHOR","PRICE"};
String rec = "";
for (int i=0; i <fieldNames.length; i++)
rec +='\"'+fieldNames[i]+'\"';
rec+=",";
if (rec.endsWith(",")) rec=rec.substring(0, (rec.length()-1));
writing.println(rec);
//write values from result set to file
rec +="\""+ob+"\",";
if (rec.endsWith(",")) rec=rec.substring(0,(rec.length()-1));
writing.println(rec);
writing.close();
catch(Exception ex)
ex.printStackTrace();
public static void main(String arg[]) throws Exception
Exporting ex= new Exporting();
}Could anyone Please modify my code and help me out.
Thank you for your service
Cheers
Jofin -
Duplicate checking based on the content of the incoming file
Hi,
We have a requirement where in we have to check whether a file has been duplicated or not based on the contents of an incoming file.The threads which I have seen in SDN deal with the duplicate checking based on the filename of the incoming file.
The incoming file has the following structure :
Recordset Occurance-1
|....... Idoc Occurance 1...unbounded
|...... segment Occurance 1
We are required to make a check based on certain fields which occur in the segment.There are about 4 fields which we will have to take from the incoming file and carry out the check.These 4 fields exist in different segments.We will have to update a ztable with these 4 fields and then perform an rfc lookup to check for the contents of the incoming files with this table,and reject or process the file based on whether the entries exist in the table or not.
Please let me know if there is any way this can be achieved.
Appreciate if anyone could help me on this.
Thanks and Regards,
IndujaSAP PI 7.1 Mapping Enhancements Series: Graphical Support for JDBC and RFC Lookups
Use this crazy piece for any RFC Mapping Lookups!
The specified item was not found.
https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/5877---- [original link is broken] [original link is broken] [original link is broken]
Imp
SAP NetWeaver Process Integration 7.1: Mapping Enhancements Blog Series
SAP PI 7.1 Mapping Enhancements Series: Mapping Enhancements Demo
/people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler
How to check JDBC SQL Query Syntax and verify the query results inside a User Defined Function of the Lookup API
The specified item was not found.
The specified item was not found.
Making CSV File Lookup Possible In SAP XI !!!
SAP PI 7.1 Mapping Enhancements Series: Parameterized Message Mappings
https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/1888-----Imp [original link is broken] [original link is broken] [original link is broken]
Triggering XI Alerts from a User Defined Function
Aspirant to learn SAP XI...You won the Jackpot if you read this!-Part II -
I have a mid year 2007 24 inch iMac and will be purchasing a new 27 inch Retina iMac, what is the easiest way to transfer the data and files from my old machine to the new one?
Following up on this thread,
I have a new iMac on the way and my current is from 2008, never had a problem but I am sure there are internal issues that I would prefer not to transfer.
I have no issues other then the slowness in certain programs and that is the main reason to buy a new one.
Programs like numbers and pages seem to take a longer time to open after I update to Yosemite.
I only use 272GB of 500 GB, my memory is 4GB and I am upgrading to 8Gb and bought the 4.0 processor.
Question:
Is there a way to manually transfer items or would that be a waste of time in that if there are issues they could be anywhere and would transfer anyway? -
I recently purchased a new iMac with an 1 Terrabyte external drive. I want to transfer my files from my old iMac to the external drive, but I'm afraid that doing that will compromise the use of the external drive on my new iMac. I have not downloaded the external drive's software onto my old Mac because of this concern. May I simply "drag and drop" the contents I want transferred to the external drive, then set up my new Mac with the drive and download there? or is there a better procedure? Comments? Help?
If your intention is to copy a just documents and data (word processing files and music for example) then yes, you can use drag and drop. If you want to transfer data and applications and permissions, it would actually be easiest to connect the drive to your old computer and turn on TimeMachine. Once TM is finished, connect the drive to your new computer and restart it holding the option key to get into Recovery mode. Then you can use the restore from TM option to transfer your data and programs to the new computer.
-
Good afternoon ladies and gentlemen!
My question concerns the impossibility to open RAW-files directly from the program Adobe Bridge. At the moment when you open a RAW-file from Adobe Bridge by double-clicking, RAW-file is opened only in Photoshop. In the settings Adobe Bridge - in "open RAW-files by double-clicking in Adobe Camera Raw» box is checked. When you try any changes in the settings Adobe Bridge system displays a message:
Bridge's parent application is not active. Bridge requires that a qualifying product has been launched at least once to enable this feature.
The entire line of Adobe products on my computer updated to the latest updates. Previously, a family of products Adobe Photoshop on your computer is not set. Computer - PC, Windows 7 Enterprises.<moved from Adobe Creative Cloud to Bridge General Discussion>
-
How to extract the contents of the Jar file?
Hello,
Can anyone tell me how to extract the contents of the Jar file?
An example will be highly appreciated.
Thanks.From command line, or from within a java application?
Kaj
Btw. Why do you need to do it. You do know that you can add jars to the classpath and read resources from them without extracting the file? -
Updating content of index.html file of J2EE Engine
Hi,
I would like to update the content of index.html file, which is located under D:\usr\sap\NSP\JC01\j2ee\cluster\server0\apps\sap.com\com.sap.engine.docs.examples\servlet_jsp\_default\root\index.html.
I have requirement to change the html file content with latest news and we want to access this latest news through http://host:port/index.html ( to avoid authentication to server). In this html file I will plase link to connect to portal.
The problem is updated content of this html file is not displaying in the browser. It is taking from cache. How to avoid this cache problem.
ThanksHello,
I think you wish to change your logon screen, this will not be done simply by changing the index.html
Please check this link for more information:
http://help.sap.com/saphelp_nw70/helpdata/EN/ff/c7de3fc6c6ec06e10000000a1550b0/frameset.htm
Regards,
Siddhesh
Edited by: Siddhesh Ghag on May 21, 2008 1:54 PM
Maybe you are looking for
-
See above.
-
Requesting help with using "doc.newPage" ...
Hi, I am using Acrobat Professional 8.1.2 and I would like to add a blank page to an open document. Is there anything wrong with the following Javascript code: // Insert Blank Page app.addMenuItem({ cName: "Insert Blank Page", cParent: "Tools", cExec
-
MM_validateForm errors in Firefox
Hi, I have a website that uses the MM_validateForm script from Dreamweaver. It would seem that it is working fine to validate all the fields, except for the email input field. In IE it ignore it completely (you can submit the form without filling in
-
Need Help About AC or battery or pc :(
Hello! i am kinda new to the forum,i have GT70 2pe dominator pro laptop(bought from ibuypower) When i play demanding games,my ac unplugs itself from the laptop i dont know what to do ,i updated ec,bios,did the ec reset,battery calibration(from msi su
-
Computer shuts down and restarts...
For the past several days, my computer has greeted me in the morning with a message saying... there was something wrong, computer had to shut down... it auto restarts. I send the report to Apple. Why would a newer iMac shut down all the time like thi