Writing plain-text files in UTF-8 encoding under MacOSX

Hello forums,
I've run into some problem writing text-files under MacOSX. I've tried several methods of writing, the current one I'm using is as follows;
private void stringToFile(File file, String string) throws IOException
    OutputStream fout = new FileOutputStream(file);
    OutputStream bout = new BufferedOutputStream(fout);
    OutputStreamWriter out = new OutputStreamWriter(bout, "UTF-8");
    out.write(string);
    out.close();
}However, when I open the file letters other than A-Z appear corrupted in Text-Edit, though in BBEdit the file is identified as UTF-8 without BOM. (still corrupt.)
The application uses some components I am not so familiar with, which makes trouble-shooting less of a breeze.
It is a spring-framework web-app, and the string to be written is passed to the application through a HTTPClient.
The string itself is constructed by
MultipartFile content = multipartRequest.getFile(CONTENT_PARAM_NAME);
String contentStr = (content != null) ? new String(content.getBytes(), "UTF-8") : null;and is created client-side by
new FilePart("content", new ByteArrayPartSource("content", strContent.getBytes()), "", "UTF-8")I would appreciate any clues you have hinting towards a solution.
I have tried to isolate parts by f.ex. writing a fixed string (which still would not work properly, which leads me to think that the HTTPClient/Spring part is not to blaim).
Message was edited by:
joakim.back

Good idea,
I'm now ensuring that the hashcode of the clientside and serverside String match, supply the bytes as UTF-8, and write it properly with
private void stringToFile(File file, String string) throws IOException
    BufferedWriter out = new BufferedWriter(
                new OutputStreamWriter(
                            new FileOutputStream(file), "UTF8"));
    out.write(string);
    out.close();
}I adjusted the stringToFile earlier, so I'm not sure wether the old code still works.
TextEdit under MacOSX still view the files as corrupt, but BBEdit and EditPlus under windows view the result fine.
Lessons learned? Beeing very careful about identifying sub-tasks and dealing with them separately.
..ofcourse, my job is not done since the damned applescripts dealing with the output treats the files as TextEdit do, but that's a task for tomorrow.
Thank you for your assistance!

Similar Messages

  • Create new text file in UTF-8 format by default

    I'm working a lot with UTF-8 text files and mainly in this format. It's becoming annoying when I have to manually save every text file as UTF-8.  After several trial-and-errors, I've made up a procedure that I've put in a blog. I think I could share
    it here for those who need it.  Hope it helps.
    http://instrumenti-meliora.blogspot.com/2014/04/create-new-text-file-in-utf-8-format-by.html

    You've made a procedure?
    Are you sure you didn't :
    Didn't what?
    https://www.google.com/#q=change+notepad+default+encoding
    Well, I'm not sure what you want me to see, but your search keywords do
    NOT make sense.  You do note change *Notepad* default encoding.  What you can change is a
    TEXT file's default encoding.
    Well, of course, if you have access to Notepad source code and you're able to change it and re-compile again, then you could really say you change Notepad's "default encoding", which I suppose would mean "default encoding every time we save".
    Why wouldn't you just provide a link (or some attribution) to the top result
    http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_programs/default-utf-8-encoding-for-new-notepad-documents/525f0ae7-121e-4eac-a6c2-cfe6b498712c
    or a link to watch this done on youtube?
    http://www.youtube.com/watch?v=GnL6smxQE9k
    The title of that forum post and Youtube video is a non-sense.  New
    "Notepad" document?  Come on!  That's apparently how a newbie think what it is and it's very likely he has not a clue what it is and what he is doing.  And what if I don't use Notepad to create such file?  If I
    use UltraEdit, then mine should be "UltraEdit" document and that should be different from Notepad document, correct? LOL
    The fact that you're able to find this video would also mean you're thinking like him in that the file is really called Notepad document LOL
    For your information, that's called a text file (or document if you prefer this prettier term).  It's also called plain text file.
    Now, let's see the content of both links:
    First of all, why did they tell people to create a new text file somewhere and then
    COPY it to template folder?  That's really so dumb
    LOL  Isn't it more intelligent to create such file directly INSIDE the folder?
    Secondly, their procedures are not foolproof.  What if the Windows directory is not c:\windows?  They should tell people to open %Systemroot%\ShellNew instead.  I suppose they don't even know how this folder is called because
    nowhere is the term "template folder" ever mentioned.
    Thirdly, what if that folder doesn't work for unknown reason (which might happen in XP)?  Did they give any hint to a "failover" folder?  No, they didn't.  But I do in my procedure.
    Fourthly, they are saying as if the file name has to be "TXTUTF-8.txt", but actually we can call it whatever we like.  But smart people would have figured this out at the end.
    5 (I'd stop saying fifthly and so on LOL) I'm not sure it's necessary (or recommended) to change "fSavePageSettings" & "fSaveWindowPositions" DWORD values for Notepad as "advised" in that answer.
    As a side-note, I don't know what
    http://www.pc1news.com/saving-changes-to-notepad-configuration-1216.html is supposed to give but when I open this, I got some uTorrent warning.  Really seems like some malware webpage which tries to deceive people!
    I actually searched how a (generic) new file is created and started from there.
    So, maybe next time when you want to criticize or discredit somebody else, try to be more expert first? ;)

  • Read a text file before knowing the encoding

    Hi,
    I've wrote a AppleScript to adjust time delay of *.lrc file(txt file but different extension).I only got a messed up text, in other aspect, it works well. I understand applescript read the text file using the wrong encoding, but I can't just set the encoding to UTF-8, for it can be UTF-8 and it can be Shift-JIS, Big5 andGB18030 as well. I don't know how to open text without getting messed up and write the result to a new text file on desktop using UTF-8 encoding. Can anyone help me with this? Thanks in advance.
    Code:
    on run
      set _lrcFile to (choose file)'s POSIX path
      display dialog "Time to delay (sec):" with title "Adjust LRC Delay" default answer "-0.5"
      set _timeDelay to text returned of result
      try
      set _timeDelay to _timeDelay as real
      on error
      display dialog "Input must be a real" with title "Error" buttons {"Stop"} default button "Stop"
      error number -128
      end try
      set _paraList to paragraphs of (read POSIX file _lrcFile)-->I don't know how to read text file properly here.
      set _newLrc to ""
      repeat with _para in _paraList
      set _timecode to do shell script "sed 's/\\[\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}.[0-9]\\{2\\}\\)\\]\\(.*\\)/\\1 \\2/'<<<" & quoted form of _para
      if _timecode as string is not (contents of _para) then
      set _timecode to words of _timecode
      set _min to (item 1 of _timecode) as integer
      set _sec to (item 2 of _timecode) as real
      set _sec to _sec + _timeDelay
      set _min to _min + _sec div 60
      set _sec to _sec mod 60
      set _sec to (round (_sec * 100)) / 100
      if _min < 10 then
      set _min to "0" & _min as string
      else
      set _min to _min as string
      end if
      if _sec < 0 then
      set _sec to "00.00"
      else if _sec < 10 then
      set _sec to "0" & _sec as string
      else
      set _sec to _sec as string
      end if
      if (count of _sec) < 5 then
      set _sec to _sec & "0"
      end if
      set _lyrics to do shell script "sed 's/\\[\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}.[0-9]\\{2\\}\\)\\]\\(.*\\)/\\3/'<<<" & quoted form of _para
      set _newLrc to _newLrc & "[" & _min & ":" & _sec & "]" & _lyrics & return
      else
      set _newLrc to _newLrc & contents of _para & return
      end if
      end repeat
      -->write _newLrc to destop here (using UTF-8 encoding)
    end run
    Sample of *.lrc and the result after delaying 0.5s.

    Hope this post will help people doing their homeworks...
              StringBuffer tmpBuffer = new StringBuffer();
              try {
                   URL url = new URL("http://.../test.txt");
                   URLConnection urlconnection = url.openConnection();
                   long l = urlconnection.getContentLength();
                   tmpBuffer.append("Content Length = " + l);
                   BufferedReader in =
                        new BufferedReader(new InputStreamReader(url.openStream()));
                   String line;
                   while ((line = in.readLine()) != null) {
                        tmpBuffer.append("\n" + line);
                   in.close();
              } catch (Exception e) {
                   //System.out.println(e.toString());
              if (tmpBuffer != null) {
                   wdContext.currentContextElement().setZoneMessage(
                        tmpBuffer.toString());

  • TextEdit - Plain Text Files That Open In Windows?

    Hi. Just got an iMac. I've been trying to make plain text files in TextEdit that show up correctly in Windows on a PC. I've tried saving the same document in 4 different formats:
    - Plan Text Unicode (UTF-8)
    - Plain Text Unicode (UTF-16)
    - Plain Text Western (Mac OS Roman)
    - Plain Text Western (Windows Latin 1)
    But none of these look right on a PC. All of the line breaks I've entered show up replaced by black rectangles. Why is this?
    What format should I save as in TextEdit, to create Plain Text files that are compatible with both PC and Macs?

    First, note that TextEdit does not create plain text files, it creates rich text files (.rtf). If you truly want plain text, try the free TextWrangler:
    http://www.barebones.com/
    As to the line break problem, Macs use just a carriage return as the end-of-line character, while Windows uses a carriage return followed by a line break character. At least, that's how I understand it. Most likely, whatever app you're using on Windows is dumb enough that it can't figure out what to do with the Mac line endings. TextWrangler will let you change the line breaks, so you could use it to create plain text files with Windows line breaks. Of course, that doesn't help if you didn't really want plain text (ie, absolutely no styling, just raw text).

  • How to load data in plain-text file into database by using EJB?

    Hi,
    We need to develop an on-line application which requires us to load input data
    from a selected plain-text file on the Web server (iplanet server) into the backend
    oracle database. How could I use EJB to make it happen? it seems like using Entity
    EJB is not feasible.
    Really appreciate your help!
    Corona

    Hi Corona,
    "Corona Fang" <[email protected]> wrote in message
    news:3f3b0ea3$[email protected]..
    We need to develop an on-line application which requires us to load inputdata
    from a selected plain-text file on the Web server (iplanet server) intothe backend
    oracle database. How could I use EJB to make it happen? it seems likeusing Entity
    EJB is not feasible.If you are talking about loading thousands of records,
    the preferable way is using plain JDBC calls utilizing
    batch methods.
    Regards,
    Slava Imeshev

  • Save results of javascript operation to a plain text file

    Hi,
    How do you save to a file using Acrobat javascript? Not a PDF file - I know how to do that - but to a plain text file.
    I have javascript that searches through a PDF document and generates some output. I can send the output to a Report (in PDF format, obviously) or to the console, but I can't see how to send it to a plain text file, which is what I need.
    Any assistance gratefully appreciated.
    Thanks,
    Tim.

    Ah, great, yes that seems to do what I want.
    However, I get an error ...
    My code is as follows:
    function CreateOutput()
         // assembles text and puts it into the variable: output
         // e.g.:
         output = "Hello, world";
    var output = "";
    CreateOutput();
    this.createDataObject("testfile.txt", output);
    Unfortunately I get this error and I don't understand it!
    InvalidGetError: Get not possible, invalid or unknown.
    Doc.pageNum:6:Batch undefined:Exec
    Obviously I'm doing somethign wrong ... but what?
    Thanks very much,
    Tim.

  • PI removing blank spaces at the end of the lines in a plain text file

    Hi -
    I have an interface that transfers a file via FTP. I defined both the sender and receiver to transfer either Text or Binary but the interface removes every blank space I have after the last character. The file is a fixed lenght file.
    Example:
    Original file:
    Hello world(space)(space)(space)(space)(space)(space)(space)(space)(eol)
    where (space) is the space character and (eol) is the end of line char.
    File after it is received.
    Hello world(eol)
    I already defined the parameter Row.fieldFixedLenghts with 10164 which is the lenght of the lines of the file.
    Any ideas why it may be happening?
    Thanks,
    Carlos.

    Hi -
    I tried both the parameters:
    xml.fieldContentFormatting
    structure.fieldContentFormatting
    The received file still has the problem. All the blank spaces are cleared out.
    The file is a plain text file not an XML file. May this be the issue?
    Thanks,
    Carlos.

  • [svn:fx-trunk] 7661: Change from charset=iso-8859-1" to charset=utf-8" and save file with utf-8 encoding.

    Revision: 7661
    Author:   [email protected]
    Date:     2009-06-08 17:50:12 -0700 (Mon, 08 Jun 2009)
    Log Message:
    Change from charset=iso-8859-1" to charset=utf-8" and save file with utf-8 encoding.
    QA Notes:
    Doc Notes:
    Bugs: SDK-21636
    Reviewers: Corey
    Ticket Links:
        http://bugs.adobe.com/jira/browse/iso-8859
        http://bugs.adobe.com/jira/browse/utf-8
        http://bugs.adobe.com/jira/browse/utf-8
        http://bugs.adobe.com/jira/browse/SDK-21636
    Modified Paths:
        flex/sdk/trunk/templates/swfobject/index.template.html

    same problem here with wl8.1
    have you sold it and if yes, how?
    thanks

  • Are plain text files treated differently in SP 2010 than MOSS 2007?

    We just moved to SP 2010 a week ago.  A user just contacted us asking why the files she accesses are not displaying.
    When she accessed these plain text files in MOSS 2007, they displayed within IE as a full page of text.
    When she accesses these now in SP 2010, she is prompted to download the file.
    These files do not end in .txt - they are names such as 2013.09.20 or whatever.
    Is there a way to configure 2010 to display, without any interpretation, plain text files within the browser?
    Thank you.

    Hi ,
    According to your description, my understanding is that you could not access the txt files with browser after migrading to SharePoint 2010..
    Whether this issue occurred if you upload a new txt file to a library.
    In my testing, everything worked well. The Open Documents in Client Applications by Default feature was acitve, and in the Library Settings->Advanced settings, ‘Use the server default(Open in the client application)’ was selected. When I clicked the file
    name, it promted a dialog like the below, I selected ‘Read-Only’, and clicked OK, the file could open with browser.
    Please go to IE->Tools->Internet Options->Programs->Manage add-ons, enable all add-ons related to SharePoint, compare the result.
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • [SOLVED] Thunar sees both '.doc' and '.txt' as plain text files...

    Hello,
    I'm using Thunar as my file manager. However, it sees both '.doc' and '.txt' files as "plain text files".
    This means that I can't make the .doc files open with OpenOffice and the .txt files open with a plaintext editor, because whenever I change the program association of one, the other changes.
    How to fix that? (looks like a MIME-type issue).
    Thanks.
    Last edited by Renan Birck (2009-08-14 15:57:05)

    DaVince wrote:Open /usr/share/mime/globs and /usr/share/mime/globs2, find the lines that assign *.doc to the plaintext mime type, and remove them. Restart Thunar, problem solved.
    Finally it works. Thanks!

  • 'Plain text' files taking up 12gb

    Hi,
    I'm hoping someone can help me. I've recently been getting warnings that my start up disc is almost full. So I moved many photos and music files to an external HD and managed to free up 20gb.
    I then ran 'disc inventory' which showed that next to iTunes and movie files, 'plain text' files, 27,000 of them were taking up 12gb and 65,000 documents 11gb.
    Can someone please tell me where these files will be found on my mac as they need to be sorted - I've read that this could be a virus but what is the best way of combating this?
    There is no way I have this many files or documents and need to know how they are being stored!
    Thanks everyone

    bump

  • Font Used For Quick Look Plain Text Files?

    Hi,
    Does anyone know what font Leopard uses when you Quick Look a plain text file? It's one that isn't anti-aliased. I can't seem to find it anywhere in my Font Book.

    You could override that with code in userContent.css, either for all websites or for specific websites.
    *http://kb.mozillazine.org/userContent.css
    <pre><nowiki> pre{font-family:monospace!important}
    @-moz-document domain(svn.uni-konstanz.de){
    pre{font-family:monospace!important}
    }</nowiki></pre>

  • Plain text files appeared from nowhere in my finder window

    I have a whole bunch of plain text files that have appeared in my finder window when searching in my user profile at the stage where I can view documents, desktop, music etc [sorry not sure what this is called and wanted to make obvious what I'm talking about].
    Can anyone help. I have no idea what these files are, but they look empty.
    Have I hit a view hidden files button somewhere that I can't find again? Can I just delete them all?
    Thanks for the help, this forum has been very useful for a number of things!
    Nick

    Hi nick,
    You have navigated to your home folder. (/Drive/Users/shortname/)
    Some programs will automatically save files there. You can delete them if you want but that may destroy settings in the app that put them there. How long was it since you last viewed the visible files in your home directory? Have you installed any new programs since then? What are the names of the files and can you infer from them where they came from? You can always try moving the files to another folder (without deleting them) and then see if you are suddenly missing any settings in a new app or if they are replaced. Might help you figure out who is putting them there.
    Hope that helps.
    edit: There is no view hidden files button unless you installed a program which specifically makes them viewable, or were playing around in terminal I suppose.
    Message was edited by: taylor.henderson

  • Number format changed after opening a plain text file in Excel

    Hi,
    I have an urget need to understand about how to open a plain text file in Excel with numbers displayed as is. The text file is tab delimited. Right now, extra digits (0, or 00 ) are added. For example, 31:16 from text file is displayed as 31:16:00,
    15:0 becomes 15:00, 6:5 becomes 6:05. How to display the numbers as they are in the original text file?
    Thank you very much for the help.
    Amy

    This is a annoying problem.
    Excel will try to guess the data type if you leave the cell formatting as general.This happens a lot with specific numerical entries that could be confused as dates.e.g. 12:0,1-5 etc.Unfortunatley We can't tell Excel to stop reading it as a date, but what you
    can do is tell it to display the date how you want it.
    In addtion,in order to avoid confusion and keep track of troubleshooting steps, we usually troubleshoot one issue per thread. So if you need any further help, please create a new post.Thanks for your understanding.

  • Boot Camp Update 2.1: plain text file?

    Hi,
    in order to install the Service Pack 3 in my Windows XP partition, Apple recommends to upgrade the Boot Camp to version 2.1.
    I downloaded the BCUpdateXP.exe but it is label by Mac as "plain text" file, so I'm not able to run it and I don't know how to install the upgrade.
    What should I do?
    Thanks!

    Can you confirm with us that you have Boot Camp version 2.0 installed currently? This is because boot camp version 2.1 will ONLY install on if the previous version (2.0) is already installed.
    If your current version is not 2.0 then please insert the leopard installation disk in your CD/DVD drive while booted into Windows. This will begin installation of the 2.0 boot camp drivers. Reboot once completed. After that you can install the boot camp 2.1 drivers and it should install and complete.
    Axel F.

Maybe you are looking for

  • Setting Default Values in PO - Multiple Account Assignment

    Hello Experts, How do we set defalut values for the Field "Partial Invoice" in the Account Assignment Tab(Multiple Acc Assignment) of Purchase Order/Purchase Requisistion. This field is  not available in Personal settings of "PO Item", also there is

  • Import sheduling agreement

    Hi, Here i run the cycle of import sheduling agreement , ME31L- ME38 -MIRO(Custom invoice) - MIGO 103 & 105 - MIRO (MATERIAL INVOICE). But agreement is made up in date 01/04/2008 that time exchange rate is different,and at the time of custom invoice/

  • Problem regarding off-cycle payroll

    Hi experts, I have question about of-cycle payroll. This is the first time I want to run off cycle payroll 1.I hired one staff after payroll run this month. If 'mI using infotype 0267 , Do I have to maintain infotype 0008. For example, this staff sho

  • Overlaping Elements in SAPScript

    Hi Experts, I m trying to do one script. In the script i want a table with 8 lines as static data. For first 2 lines data(statci data)is coming properly and after the 3rd line itself data  is overlaping with eachother. It is killing my time and produ

  • Why can´t I download the new firmware?

    Yesterday I have tried to download the version of firmware (ios 4.3.2) three times through the iTunes, but I received a message saying that my time connection has expired. How can I download the new version? ThiagoFreitas