Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!

Ryan Langley

Ranch Hand
+ Follow
since May 10, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 Ryan Langley

Hello,
OSI can refer to either a suite of protocols OR a reference model. TCP/IP is also a suite of protocols, and is the more widely used one.
Cheers,
RL
[This message has been edited by Ryan Langley (edited September 26, 2001).]
[This message has been edited by Ryan Langley (edited September 26, 2001).]
Hello,
All you would have to do is put a newline(\n) character at the end of the String you are going to add to the JTextArea, and then use the JTextArea's append(String) method to add it to the end of whatever is already in the JTextArea. For example:
JTextArea jta = new JTextArea("Welcome to chat!\n\n");
String chatString = "";
...
jta.append(chatString + "\n");
------------------
Cheers,
RL
[This message has been edited by Ryan Langley (edited July 11, 2001).]
16 years ago
Hello,
Does the line that your program is receiving from the socket end with '\r', '\n', or "\r\n"? The readline() method, according to the javadoc, will "read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed." Try seeing if you can read one character at a time, instead of one line at a time. Since it's a password, it whouldn't be extremely long. Just a suggestion, anyway. Hope this helps to lead you to a solution!

------------------
Cheers,
RL
Cool.. Glad to be of service!
16 years ago
Hello,
Here's a little something I wrote up real quick with your question in mind. I haven't tested it too extensively, but it looks like it works. I haven't tried it at all on a *NIX based system. Let me know how it works for you...


------------------
Cheers,
RL
16 years ago
Hello,
I'm not sure why you want to copy all files in one directory to another, but if you're doing it so that you can overwite/delete the original files in the initial directory then you may want to check out the renameTo() method of the File class. It can be used to effectively move the files from one directory to another. Here's a quick program I wrote to illustrate this:

I haven't tried this on extremely large files, so I don't know how fast it would work on those. Just a simple solution if that is what you're lookign for.. Good luck!

------------------
Cheers,
RL
16 years ago
Hello,
The default behavior of the File IO streams is to overwrite what was already in the file. IF you want to append, you have to specifically flag it in the constructor to do so. If the data is important to keep around, or is needed for auditing or something, then I would make a back-up copy of the file before you overwrite it. You can use whatever schema you want for that, and it depends on how long you want to keep back-up copy's around. Here is a basic app that I wrote up real quick to show some of the ways you can use File IO. Hope this helps in answering your question!


------------------
Cheers,
RL
16 years ago
Hello,
One possible alternative could be to use the RandomAccessFile Class. I'm not sure what your program totally entails, but you could save the position that you want to use as a checkpoint, and later when you wanted to return there, all you would have to do is use the seek() method and pass it the position integer. Hoep this will help you figure it out!

------------------
Cheers,
RL
16 years ago
Try using java.util.GregorianCalendar
The java docs even do a good job of showing how to get each particular part of the date and time.

------------------
Cheers,
RL
16 years ago
Hello,
RandomAccessFile allows you to seek to a position in a file, say 5 characters/bytes after a newline character ('\n'). And then read x characters/bytes from that position. You could then seek to a different part of the same file, say 5 characters/bytes after the next newline character, and read some more characters/bytes. Unlike the other Readers/InputStreams it is not sequential access to a file, but random access to a file. You can access any part of the file at any time, as opposed starting from the beginning of the file and having to read characters/bytes to get to the part of the file you really want to read. Look it up in the javadocs. Here's a quick example that will read the 5th character of everyline and print it to screen:

------------------
Cheers,
RL
[This message has been edited by Ryan Langley (edited June 25, 2001).]
16 years ago
Hello,
How do you distinguish the records? Is there a primary key or a unigue field in the record that you can use for comparisons? If so, I would read all the keys and make two separate lists of them. I would then discard the duplicate keys from the list that is from the file that is going to be appended, and then read through that file and append the records with those keys. This won't be too tough to do if you use RandomAccessFile. Hope this helps!
Cheers,
RL
16 years ago
wait() (within a synchronized code block of course) will cause the thread to stop until it is interrupted.
start() (used with a Thread based object) will in effect branch a new thread off from the currently executing thread. Both threads will run (theoretically) in parallel.
sleep() will make the currently running thread stop executing for a specified period of time, and then continue.
notify() will interrupt a thread that has called wait().
yield() will cause a thread to suspend operation so that other threads of equal or higher priority will be allowed to run by the thread scheduler, which could be the same thread that called the yield() method. This is usually used if a thread is carrying out a complex computation so that other threads can have a chance to run.

Originally posted by Nigel Patching:
Could someone tell me which of these methods directly stop a thread:
wait()
start() called on a new thread
sleep()
notify()
yield()



------------------
Cheers,
RL
Hello,
Try using the BufferedInputStream and BufferedOutputStream classes. The Reader/Writer classes only read and write character data, whereas the Input/Output stream classes read and write byte data.

------------------
Cheers,
RL
17 years ago
Hello,
I don't think this exception has anything to do with what you are trying to do with the files. NumberFormatException indicates that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format. You aren't doing this with any of the code you have displayed here. It looks like it is happening under the Simple classes paint method somewhere.
------------------
Cheers,
RL
[This message has been edited by Ryan Langley (edited June 14, 2001).]
17 years ago
Hello,
From your questions I think that basically you are asking that if you have an object, say object A for example, you want to know if two threads, say thread B and thread C, can access it at the same time. This is possible, but it may not be a good thing. If you know that the methods on A that will be called by B are methods that are never called on A by C then you won't have any problems. BUT if both threads are accessing the same methods in the object, then you will have to synchronize those methods to make sure that the threads don't execute on it at the same time. When the methods are synchronized, a thread will lock the object while it executes within it so that any threads that attempt to access the object while it's locked will enter the wait state. Then, when the thread exites the synchronized method, the waiting thread(s) will then attempt to access the object again. When one obtains a lock, the others will again wait for it to free up before continuing. Hope this helps in answering your question!
Cheers,
RL