Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

some questions

  Asked By: Emily    Date: Nov 12    Category: Java    Views: 630

I have some questions, hope you help me.
1) I have a directory with 49 files, I want to read
each of the files in a directory and create another
directory with 49 files. I mean I read from the first
files and create the second files in another
directory. Would you please tell me how should I
manage to do it? I mean what is its code?

2) I want to delete the space from my string, I know
it there is a function “trim()” , but I don’t know how
should I use it?

3)is it possible that in Java, I have 3 tables, I want
to read from one table and write in another table. I
have difficulty with working with “insert into ….” ,
how should I do it?
Would you please show me a sample of it?

4) in one of my classes, I call another class by
creating a new of it, but it says it is not possible
and says that it doesn’t resolve the name of the
class. What is its problem?
I am working with JDK 1.4 and textpad 4.7 ,



3 Answers Found

Answer #1    Answered By: Omar Walker     Answered On: Nov 12

1) You mean to copy files, right?? Try using class  java.io.File or
java.io.RandomAccessFile. I'm sorry, I can't give you the code yet,
but if you have the java  Documentation, you can search it for more
reference. But if I have time, maybe I can try and give you the code.

2)As far as I can remember, "trim()" only delete  spaces in front and
back of string, so if your original string  is " This is a
string ", and you call  trim(), the result will be "This is a
string". Here is the code :
String myString = new String(" This is a string ");
String myString2 = myString.trim();
myString2 will be "This is a string"

3) I don't know

4) Have you set your classpath correctly??? Or maybe you can consider
using NetBeans IDE (http://java.sun.com/j2se)

Answer #2    Answered By: Bonnie Hughes     Answered On: Nov 12

you can use the command
String filename = "test.txt";
File f = new File(filename);
and so on
There is directory  command as well by which you can read  all the file
exact sentence i do not remembering

directory d = new directory(c:\k2");
Enumeration enum = d.Elements();
and so on

(ii) for deletion of space  use
String s1 = "hello ";
s1 = s1.trim();

(iii) use simple jdbc command for this
import java.util.*;
import java.sql.*;
public class  data2 {
public static void main(String argv[])
String str1,str2,str3;
Statement s1;
Connection con;
ResultSet rs,rs2;
con = DriverManager.getConnection("Jdbc:Odbc:jemp"); //jemp is the odbc name
s1 = con.createStatement();
str1 = "select * from emp";
// rs2 = "insert into emp2 where name =" ' " + str1" and " '"code = &str2"
rs = s1.executeQuery(str1);
str2 = rs.getString("name");
str3 = rs.getString("code");
System.out.println("Name :"+str2+ " Code: "+str3);
}catch(Exception e) {}

iv) for the fourth try to do work on command prompt.
The only criteria is class called should be in the same directory.
see if you have already compiled the java  file that you are calling

Answer #3    Answered By: Percy Morgan     Answered On: Nov 12

copy might not work for you. This only works if both files  (the new
and the old one)
are on the same partiton. For example under Linux you cannot copy from /tmp
to /usr/local.
Under Windows you cannot c:\.. to d:\..... The copy method fails under most
Sun has confirmed that this is not a bug because it works the way they
It's stupid but that's the way it is.
You should open the first file, create  the second one and do a binary copy
inside a while loop
to be sure.

Didn't find what you were looking for? Find more on some questions Or get search suggestion and latest updates.