Java Convert a File's Character Encoding from UTF-8 to UFT ...

文章推薦指數: 80 %
投票人數:10人

To add a utf-8 BOM to a file is just a matter of prepending these 3 bytes to the file: 0xEF 0xBB 0xBF. This may be difficult in some programming languages, or ... Chilkat• HOME•.NETCoreC# •Android™ •AutoIt •C •C# •C++ •Chilkat2-Python •CkPython •ClassicASP •DataFlex •DelphiActiveX •DelphiDLL •Go •Java •Lianja •MonoC# •Node.js •Objective-C •PHPActiveX •PHPExtension •Perl •PowerBuilder •PowerShell •PureBasic •Ruby •SQLServer •Swift2 •Swift3,4,5... •Tcl •UnicodeC •UnicodeC++ •VB.NET •VBScript •VisualBasic6.0 •VisualFoxPro •XojoPlugin JavaExamples WebAPICategories ASN.1 AmazonEC2 AmazonGlacier AmazonS3 AmazonS3(new) AmazonSES AmazonSNS AmazonSQS Async AzureCloudStorage AzureServiceBus AzureTableService Base64 BouncedEmail Box CAdES CSR CSV Certificates Compression DKIM/DomainKey DSA Diffie-Hellman DigitalSignatures Dropbox DynamicsCRM EBICS ECC Ed25519 EmailObject Encryption FTP FileAccess Firebase GMailRESTAPI GMailSMTP/IMAP/POP Geolocation GoogleAPIs GoogleCalendar GoogleCloudSQL GoogleCloudStorage GoogleDrive GooglePhotos GoogleSheets GoogleTasks Gzip HTML-to-XML/Text HTTP HTTPMisc IMAP JSON JSONWebEncryption(JWE) JSONWebSignatures(JWS) JSONWebToken(JWT) JavaKeyStore(JKS) MHT/HTMLEmail MIME MSStorageProviders MicrosoftGraph NTLM OAuth1 OAuth2 OIDC Office365 OneDrive OpenSSL Outlook OutlookCalendar OutlookContact PDFSignatures PEM PFX/P12 PKCS11 POP3 PRNG REST RESTMisc RSA SCP SCard SFTP SMTP SSH SSHKey SSHTunnel ScMinidriver SharePoint Socket/SSL/TLS Spider Stream TarArchive Upload WebSocket XAdES XML XMLDigitalSignatures XMP Zip curl       (Java)ConvertaFile'sCharacterEncodingfromUTF-8toUFT-8-BOM Toaddautf-8BOMtoafileisjustamatterofprependingthese3bytestothefile:0xEF0xBB0xBF. Thismaybedifficultinsomeprogramminglanguages,oritmaybetrivialineither.Therefore,theChilkatsolutionyouseeheremightbehelpful,orinalanguagesuchasC++,theChilkatsolutionisn'treallynecessarybecauseit'seasytodoyourself. ChilkatJavaDownloads JavaLibsforWindows,Linux,AlpineLinux,MACOSX,Solaris,FreeBSD,OpenBSD,RaspberryPiandothersingleboardcomputers JavaLibsforAndroid importcom.chilkatsoft.*; publicclassChilkatExample{ static{ try{ System.loadLibrary("chilkat"); }catch(UnsatisfiedLinkErrore){ System.err.println("Nativecodelibraryfailedtoload.\n"+e); System.exit(1); } } publicstaticvoidmain(Stringargv[]) { //ThisexampleassumestheChilkatAPItohavebeenpreviouslyunlocked. //SeeGlobalUnlockSampleforsamplecode. CkCharsetcharset=newCkCharset(); charset.put_FromCharset("utf-8"); charset.put_ToCharset("bom-utf-8"); booleansuccess=charset.ConvertFile("qa_data/txt/helloWorld.txt","qa_output/helloWorldBom.txt"); if(success!=true){ System.out.println(charset.lastErrorText()); return; } System.out.println("Success."); } }   © 2000-2022ChilkatSoftware,Inc.AllRightsReserved.



請為這篇文章評分?