Ranet Saed

Greenhorn
+ Follow
since May 02, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ranet Saed

Hi plz if i have a text file file1.txt contains for example:
Hi Bob ?
How are You?
I need to meet u.
See u Bye

and i need to copy this file contents to another file but without line separator i need to ignore it so i want for example this file to contain:
Hi Bob ?How are You?I need to meet u.See u Bye
how can i do that???
14 years ago
Hi plz i need an argent and good help in the problem of the two files to append
14 years ago
Hi ....Thanks Samir a lot u really helped me with my problem ...i didnt take care of wut i did before...any way i want to ask about another problem i have in the same Class ...I have to append two strings but each one must be saved in a seperate text file ,so the requiered here is to append two text files ...I did that ,but the problem was that each string was in a separate line i dont know why ...for example if i have two text files file1.txt[Hi Bib how are You]
file2.txt[1243456778889990]
the result for the appending was
Hi Bob how are You
1243456778889990

but sure i need this result:
Hi Bob how are You1243456778889990
my code is as folowing:

/ create writer for file to append to
BufferedWriter out = new BufferedWriter(
new FileWriter("file1.txt", true));
// create reader for file to append from
BufferedReader in = new BufferedReader(new FileReader("file2.txt"));
String str;
while ((str = in.readLine()) != null) {
out.write(str);
}
in.close();
out.close();

so how can modify my code to make the right apending as I need???
14 years ago
I have the same problem it gives me an ecxeption ,I tried your code Steve but i had this statement which you put in the exception:
Not a number on the last 4 characters
but the problem is the recv_message is as following:
Hello Bob, how are you? I am going to go to the movie tonight. I plan to see Gonewith the Wind. I really like Clark Gable. Would you like to go with me? I would really like to have some company. Your friend, Alice5113350515586806264156901277970003516182249744328267808527911381008517422384937086806339111024080220

i got it from appending two files
the last four characters 0220 i got them from representing the length of the message in four characters by this code :

String My_Meesage_Length = "" + len;
//Confirm number of characters in the string.
if((My_Meesage_Length.length() > 4)
|| (My_Meesage_Length.length() <= 0)){
System.out.println("Message length error.");
System.exit(0);
}//end if
//Prepend leading zeros if necessary
if(My_Meesage_Length.length() == 1){
aliceMsgLenAsStr = "000"
+My_Meesage_Length;
}else if(My_Meesage_Length.length() == 2){
My_Meesage_Length= "00" + My_Meesage_Length;
}else if(aliceMsgLenAsStr.length() == 3){
My_Meesage_Length = "0" + My_Meesage_Length;
}else if(My_Meesage_Length.length() == 1){
My_Meesage_Length = "000"
+ My_Meesage_Length;
}
System.out.println(My_Meesage_Length);

so this may makes the problem more clear...
so by this the last four characters are numbers so why it keeps give me the same problem...plz any help
14 years ago
Hi ,I have a text file and it contains a message ,I want to extract the last four characters in this file and then convert it to integer i did the following:
FileInputStream Received_Message=new FileInputStream ("MyFile.txt");
BufferedReader buff2=new BufferedReader(new InputStreamReader(Received_Message));

System.out.println("Your Received message is as following:");
while((recv_Message=buff2.readLine() )!=null){
System.out.println(recv_Message);
length2 += recv_Message.length();
}

four_characters=recv_Message.substring(recv_Message.length() - 4,length2);
Four_characters_Integers = Integer.parseInt(four_characters);
i sure have try and catch and defined all varibles above
but the problem it gives me this message when i use this statement:
four_characters=recv_Message.substring(recv_Message.length() - 4,length2);
the Exception is as following:
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:373)
at java.lang.Integer.parseInt(Integer.java:454)
at final_append.CopyBytes.main(CopyBytes.java:101)
Exception in thread "main"
how can i solve this??plz any help in
by idea the message is as following which i need to extract the last four characters from:
5113350515586806264156901277970003516182249744328267808527911381008517422384937086806339111024080220
so the last four characters are numbers
14 years ago
Hi ,I have a text file and it contains a message ,I want to extract the last four characters in this file and then convert it to integer i did the following:
FileInputStream Received_Message=new FileInputStream ("MyFile.txt");
BufferedReader buff2=new BufferedReader(new InputStreamReader(Received_Message));

System.out.println("Your Received message is as following:");
while((recv_Message=buff2.readLine() )!=null){
System.out.println(recv_Message);
}

four_characters=recv_Message.substring(recv_Message.length() - 4);
Four_characters_Integers = Integer.parseInt(four_characters);
i sure have try and catch and defined all varibles above
but the problem it gives me this message when i use this statement:
four_characters=recv_Message.substring(recv_Message.length() - 4);
the Exception is as following:
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:373)
at java.lang.Integer.parseInt(Integer.java:454)
at final_append.CopyBytes.main(CopyBytes.java:101)
Exception in thread "main"
how can i solve this??plz any help in
14 years ago
Hi I need to calculate the Length of a message saved in a text file so
i wrote the following code:
int len;
try{
FileInputStream Message_File=new FileInputStream
("output8.txt");
BufferedReader buff=new BufferedReader(new
InputStreamReader(Message_File));
String Input_Message=new String();
System.out.println("Your input message is as following:");
while((Input_Message=buff.readLine() )!=null){
// Calculating the the length of our message in unit of bits
System.out.println(Input_Message);
len=Input_Message.length();
System.out.println(len);}
{catch......

this will only give me the length of the last line in the Mesage not
the length of all the message ,so when I Put this statement after while
loop :
len=Input_Message.length();
System.out.println(len);
it will give null exeption:
java.lang.NullPointerException
at final_append.CopyBytes.main(CopyBytes.java:19)
Exception in thread "main"
So what i can do???


Reply
14 years ago