Why couldn't I get the contents of the a file ?

I have a txt file,I want to disply it,but all can I get is chaos.I change the file from ANSI to Unicode,It didn't work too.
why?
by the way,I add a "'# " at the tail of the file;
how can I get the correct content of the file,
the code is:
try{
FileInputStream fs=new FileInputStream("test2.txt");
DataInputStream ds=new DataInputStream(fs);
char token;
StringBuffer dd=new StringBuffer();
while((token=ds.readChar())!='#'){
dd.append(token);
System.out.println(dd.toString());
catch(IOException e){}

to make your life easy, this is a utility class i keep around...
* Open.java
* Created on 25 May 2001, 21:02
package com.moss.io;
import java.io.*;
import java.net.URL;
import java.net.MalformedURLException;
* @author  David Moss
* @version 1
public class Open extends java.lang.Object
     * Opens a file
     * @param fileName The file to open
     * @return The text string stored in <code>fileName</code>
    public static String Open(File fileName)
        String s = "";
        if (fileName.equals(null))
            return null;
        try
            String line;
            FileReader fin = new FileReader(fileName);
            BufferedReader bin = new BufferedReader(fin);
            while((line = bin.readLine()) != null)
                s += line + "\r\n";
            bin.close();
            return s;
        catch (Exception e)
            e.printStackTrace();
            return null;
        return null;
     * Opens a file
     * @param fileName The file to open
     * @return The text string stored in <code>fileName</code>
    public static String Open(URL fileName)
        return Open(new File(fileName.getFile()));
     * Opens a file
     * @param fileName The file to open
     * @param url True if the <code>fileName</code> string is represented as a URL,
     * false if its represented as a File
     * @return The text string stored in <code>fileName</code>
    public static String Open(String fileName, boolean url)
        if (url)
            try
                return Open(new File(new URL(fileName).getFile()));
            }catch (MalformedURLException e)
                e.printStackTrace();
                return null;
        else return Open(new File(fileName));
}you will probably want the exceptions thrown and the code cleande up because it is pretty bad as it is at the moment and i just can not be arsed to clean it for you.
have fun.

Similar Messages

  • Why I can not get the image file of component?

    Hello,
    I tried to get an image file from the component. After I run the code below, there is not any new file created. Could you tell me what's wrong with it?
    Rectangle d = this.getBounds();
    BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
    try {     
    ByteArrayOutputStream boutstream = new ByteArrayOutputStream();
    // save it to file
    FileOutputStream fimage = new FileOutputStream( new File( "image.png" ) );
    boutstream.writeTo(fimage);
    fimage.close();}
    catch (Exception ev){     
    System.err.println("error making jpeg image: " + ev);
    ev.printStackTrace();}

    BufferedImage bi = new BufferedImage(d.width,d.height, BufferedImage.TYPE_INT_RGB);Straight after the above line you need to put this line:
    d.paint(bi.getGraphics());
    This is what was suggested to me in this thread(http://forum.java.sun.com/thread.jsp?forum=57&thread=369379) anyway, and it worked for me!

  • Why am I not getting the buttons of Hide/Show, Refresh, Back, Home, Options ?

    Gorgeous Hello All,
    If anyone of you can please provide me a solution for the following, will help me in plentious and galore.
    Am using Adobe RoboHelp, Version 10 and IE version being 10.
    A hurdle :-
    When I File -> View -> Primary Layout : I am getting only these options of Search, Hide, Contents, Index, Glossary, Print being displayed on the screen, eventhough I have ticked for Hide/Show, Refresh, Back, Home (Home -> Advanced Properties -> Home : and declared the respective url as well) , Options  courtesy View -> Pods -> Project Set-up -> Double Click on Windows -> Double Click on NewWindow.
    Why am I not getting the buttons of Hide/Show, Refresh, Back, Home, Options when I File -> View -> Primary Layout ?
    Cheese - Vipin Nambiar

    Hey Piyush Buddy, where were you since my morning !!! :-) :-) :-)   Your simple question here made me realize where did I make the slip of my brain and now all the desired buttons are appearing on my screen. 
    I just made simple parameter changes called View -> Pods -> Single Source Layouts -> Right Click On Microsoft HTML Help -> Setted as Primary Layout (earlier my Primary Layout was setted up for Multiscreen HTML 5).
    THANKS GALORE Piyush buddy - Your simple question to me made a mammoth and galores of help to get my train on track.

  • HT2905 can someone please tell me why I do not get the delete from disk option when trying to delete duplicate items

    can someone please tell me why I do not get the delete from disk option when trying to delete duplicate items

    The content must be in the iTunes directory structure for that option to appear.

  • HT1766 Why am I constantly getting the message that I don't have enough storage space? I have upgraded to the 50GB storage plan and I am still getting the message. Help?

    Why am I constantly getting the message that I don't have enough storage space? I have upgraded to the 50GB storage plan and I am still getting the message. Help?

    That message refers to storage on your iPhone, not cloud storage. You will need to move content off your phone to make more space.

  • HT1491 Why do i keep getting the message 'Cannot connect to iTunes Store' when I have done every connection I can find? What does the error message (-1202) mean when I am on the iTunes site on my computer?

    Why do i keep getting the message 'Cannot connect to iTunes Store' when I have done every connection I can find? What does the error message (-1202) mean when I am on the iTunes site on my computer?

    Hi Velvalee,
    While there may not be specific information about that error, here is an article of steps for troubleshooting connectivity issues with the iTunes store:
    Can't connect to the iTunes Store
    http://support.apple.com/kb/ts1368
    If that article does not help, there is a link near the bottom for an additional article of advanced troubleshooting.
    Cheers!
    - Ari

  • Why can't I get the pdf to convert to publisher?

    Why can't I get the pdf to convert to publisher?

    If you are using ExportPDF, see http://forums.adobe.com/docs/DOC-1511

  • Why can't I get the Kodak Document Print App in the UK?

    Why can't I get the Kodak Document Print App in the UK?

    "Apparently it's available in the US iTunes store but not here?"
    Because Kodak has chosen not to make it available there.
    "Can't for the life of me understand why that should be!"
    You do not have to understand it for it to be so.
    You can try asking Kodak, as they make the app.

  • Why do i always get the Japanese version of JRE/JDK?

    why do i always get the Japanese version?
    i am in tokyo and i just want to get the English version of JRE and JDK. Why is it so difficult, I have been trying for the last 8 hours to find mirrors and other versions and installing all of them only to see they are all in Japanese and I don't know why. I checked my settings, my local language is German or English, i.e. not Japanese, and always I install it it's in Japanese and afterwards I get the compiler messages in Japanese and I don't understand them.
    And then... why is it so difficult to make a comment at sun? i have been to ibm's page and google, you just fill out a form send it, it takes 5 secs, here it takes 20 minutes to find where you can ask a question, then some more to fill out the questionaire...
    could you pls tell me where to get the US/english version for jre 1.4.2.x and jdk 1.4.2.x?

    You probally ARE getting the english version. If you are using a japanese version of windows or an english version of windows with the locale setting set to Japan then all of the menus (including the installer) will be displayed in japanese. So it just seems like you are installing a japanese version.
    To check your local in windows 2000 go to the control panel and then choose regional options. Then, select the general tab and change your locale to one of the English locales. Also, if you want to keep your locale setting set to Japan there are other workarounds. However, first try this.

  • Why can't I get the App "Deskconnect" on my Ipad 3.  It claims to be compatible with Ipad as well as Mac and Iphone?

    Why can't I get the App "DeskConnect" on my Ipad 3.  It claims to be compatible with Ipad, Iphone and Mac.  I was able to download onto Mac and Iphone but it is not recognized for Ipad?

    I liked the idea of this app so I went looking for it and have now installed it on my Mac, iPhone and finally my iPad.
    This app, although it will run on the iPad is actually an iPhone/iPod app, as suggested above. So the only way to get it on my iPad was to search for it as an iPhone app in the App Store app on my iPad. Then it came up as an app that I could install on the iPad.

  • Why can't i get the offer of a yahoo sign in security seal .. and a security warning from firefox

    i have an ibook g4 running osx 10.4.11
    5mar my yahoo sign in security seal did not show from either internet cafe or dial up .. 6mar i reinstalled osx 10.4.11
    after reinstall i did not get the offer to create a sign in security seal from any internet cafe or dial up
    anyone else gets the offer on the sign in page
    when using firefox i also get the following ..
    "security warning .. you have requested an encrypted page that contains some unencrypted information .. information that you see or enter on this page could easily be seen by a third party"
    why do i not get the sign in security seal offer everyone else does
    why do i get the security warning no one else does

    Welcome to the Apple Community.
    There are reports of TV Shows missing from users screens, initially it looked like this might be an issue in the UK only, but it may well be more widespread. It appears to be an issue that can't be fixed by the user, you will need to wait until this is resolved by Apple.

  • Why do I keep getting the message "key not valid for use in specified state"?

    why do I keep getting the message "key not valid for use in specified state"?

    You need to deal with Adobe Customer support.  This is a  Photoshop User forum the is also one for LR may be some on over there has encountered you problem Photoshop Lightroom

  • I have downloaded 15 versions of Firefox this week - 8 were on Wednesday. Why can't I get the latest version the first time I download instead of having to download each change even though you make 8 changes in one day. This is getting tiresome.!!!!!

    When I first pull up Firefox it often says I'm not using the latest version. I go to the download page and start the download. Then when its completed and the start page comes up it usually says I don't have the latest version. I went through 8 downloads on Wednesday January 4 before I got the latest. Why didn't I get the latest version the first time I downloaded.?

    Firefox 9.0.1 is the latest release version.
    Which page do you have set as your Homepage or Start Page?
    This - http://www.google.com/firefox - is the old Firefox Start Page used by the Firefox 3.6 and earlier versions of Firefox. Not being maintained by Google and it shows all versions of Firefox as needing to be updated, even pre-release tester versions that are months away from being released to the public at large.
    Starting with the Firefox 4 version, Firefox is using a "local" Start Page with the address of '''about:home'''. It looks similar to the old Start Page, but it isn't exactly the same.

  • Why can I not get the creative cloud to install on my MacBook Air? I keep getting an error saying I need to download a new copy

    Why can I not get the creative cloud to install on my MacBook Air? I keep getting an error saying I need to download a new copy

    Please read https://forums.adobe.com/thread/1499014
    -try some steps such as changing browsers and turning off your firewall
    -also flush your browser cache so you are starting with a fresh browser
    http://myleniumerrors.com/installation-and-licensing-problems/creative-cloud-error-codes-w ip/
    http://helpx.adobe.com/creative-cloud/kb/failed-install-creative-cloud-desktop.html
    or
    A chat session where an agent may remotely look inside your computer may help
    Creative Cloud chat support (all Creative Cloud customer service issues)
    http://helpx.adobe.com/x-productkb/global/service-ccm.html

  • HT201303 why do i keep getting the message "Please contact iTunes support to complete this transaction."?

    why do i keep getting the message "Please contact iTunes support to complete this transaction."? Oh, and I would love to contact support but they are never open for business when this happens to me so I was hoping someone knew what the heck was going on. I love my ipad and hate that I can't get the in app purchases that I need in order to advance to the next level to buy if I don't want to start the whole game again!! Please help. Let me know what you did to bypass this or get an itunes associate on the phone or what ever so I can solve this NOW!?

    You can contact iTunes support via email via this page and ask them why you are getting the message and how to resolve it (I'm not aware of any phone support for iTunes) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page

Maybe you are looking for

  • Will Pagemaker 7 work with Windows 7 (on an iMac)?

    I'm writing for my dad, 86, who has designed several books in Page Maker 7 on a PC running Windows XP. For his 5th book, he wants to switch to the iMac. So he got an iMac with the Adobe Creative Suite 3 with InDesign. Unfortunately, despite classes a

  • Question about viewing .swf in email

    My client wants to send an .swf by email. lat year the file was 975kb and when they clicked the play button the animation played immediately Yay! This year the .swf animation is 2.4 - 3 mb and I am worried the client will have to wait for it to load.

  • Can we hide a prompt in a dashboard page/

    Hi All,     I have a doubt about prompts.can we hide a prompt in a dashboard page without hide a section. Thanks, Hari.

  • Premiere Pro & Media Encoder CS6 exports 0 or 1 kB file

    Hello I'm start using Premiere Pro CS6 on the Company where I work. When I export the movie to Media encoder, I get 0 or 1kB file. Original File: MUX: MP4 Type: MPEG Movie File Size: 2,8 MB Image Size: 640 x 360 Frame Rate: 25,00 fps Progressive Sour

  • There is not enough disk space to download new messages

    I'm running 24.3.0 - this morning I was able to receive messages until a couple of hours ago and started receiving error message 'There is not enough disk space to download new messages'. I deleted over half my messages but still got error message. I