Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=C3=B8j?= Newsgroups: comp.os.vms Subject: Re: New VSI post on Youtube Date: Tue, 20 Aug 2024 14:37:26 -0400 Organization: A noiseless patient Spider Lines: 85 Message-ID: References: <66bcf876$0$717$14726298@news.sunsite.dk> <66bcfbe3$0$717$14726298@news.sunsite.dk> <66c397f6$0$716$14726298@news.sunsite.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 20 Aug 2024 20:37:26 +0200 (CEST) Injection-Info: dont-email.me; posting-host="ea6d136f1584c6f8706b0ca882e11879"; logging-data="3639750"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fyFu/A2VAmPeyEzsdT007dwBrqSuSTEY=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:e92Jr+ULy/ZBf08OQyrdwblaEw4= Content-Language: en-US In-Reply-To: Bytes: 4665 On 8/20/2024 1:38 PM, Simon Clubley wrote: > Also, no dynamic arrays built into the language itself. You need ArrayList() > to implement them or things like ByteArrayOutputStream(). At the level of Java then I think that is to be expected. A dynamic data structure requires a collection type. In C# List and T[] are different. In C++ vector and T[] are different. But Java developers should consider ArrayList to be their default choice instead of T[]. >> The java.io package may seem a bit complex, but it makes perfect >> sense when you learn the structure. >> >> The basics is: >> >> InputStream - read bytes from anything >> FileInputStream - read bytes from file >> ByteArrayInputStream - read bytes from byte array >> ... >> OutputStream - write bytes to anything >> FileOutputStream - write bytes to file >> ByteArrayOutputStream - write bytes to byte array >> ... >> Reader - read chars according to encoding from anything >> FileReader - read chars according to encoding from file >> CharArrayReader - read chars according to encoding from char array >> ... >> Writer - write chars according to encoding to anything >> FileWriter - write chars according to encoding to file >> CharArrayWriter - write chars according to encoding to char array >> ... >> >> All very systematic. >> >> On top of that there are two convenience classes to work with text >> files: >> * BufferedReader that wraps any Reader and provides a readLine method >> * PrintWriter that wraps any Writer and provides print, println and >> printf methods >> >> Remember that and you can handle 98% of cases. >> >> For the last 2% reading the docs will be needed. > > You forgot about InputStreamReader() to turn an InputStream into a Reader. :-) There are InputStreamReader to convert from InputStream to Reader and OutputStreamWriter to convert from OutputStream to Writer. And they are actually used, because some API's has classes that only has getInputStream()/getOutputStream() methods and not getReader()/getWriter() methods. All follow the model. > After all, why miss the opportunity to have two parallel sets of APIs > (byte versus character) instead of just the one API ? :-) > > Goodness knows why they didn't just add something like String's getBytes() > method to the character APIs or add character support to the byte APIs... Because InputStream/OutputStream and Reader/Writer are fundamentally different. The first transfer between an in memory sequence of bytes (-128..127 values) to an external form of same sequence of bytes (-128..127 values). The second transfer between an in memory sequence of sequence of chars aka Unicode code points (0..65536 values) usually in the form of String objects to an external form of sequence of bytes (-128..127) values often of a different length according to some encoding (UTF-8 is most common but there are hundreds of possibilities: UTF-16, UTF-32, ISO-8859-x, ASCII, EBCDIC, various non-latin). In C then wprintf/wscanf are not the same as printf/scanf either. The difference is that very few use wide in C while everybody is more or less forced to use wide in Java. Arne