Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.7.3, 1.8-beta-1
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
Because GDK makes the File method setText(String text) an alias for write(text),
and because it's possible to say both getText() and getText(String charset),
it feels clunky that there is no setText(String text, String charset).
In short, the following is annoying:
myfile.getText(charset)
...
myfile.write(text,charset) // Hm... I wish myfile.setText(text,charset) just worked here too.
It seems like adding this alias would not break anybody's code,
and would remove a silly-thing-you-gotta-remember.
I probably agree that such a method is useful, but another way to look at it is that most people use the write method (which already has two variants) unless they plan to make use of the property style notation, e.g.
but given that such notation isn't easily supported when there is also a charset argument, then by adding the new method we are creating more confusion for developers - one more thing they have to remember.
But having said that, I think it is slightly more useful than more confusing. Possible patch:
/** * Synonym for write(text, charset) allowing: * <pre> * file.setText('foo', charset) * </pre> * * @param file a File * @param charset the charset used when writing to the file * @param text the text to write to the File * @throws IOException if an IOException occurs. * @see #write(java.io.File, java.lang.String, java.lang.String) * @since 1.7.3 */ public static void setText(File file, String text, String charset) throws IOException { write(file, text, charset); }