Opening files and viewing the text

I'm trying to write a method to open a .doc file and display the text to screen, the program runs but nothing appears on the screen. Is the code below the correct way or is it flawed.
class Open implements ActionListener
          public void actionPerformed(ActionEvent event)
               try {
               JTextPane view = app.setScreen();
             BufferedReader in = new BufferedReader(new FileReader("outfilename.doc"));
             String str;
             while ((str = in.readLine()) != null) {
             view.setText(str);     
        in.close();
    } catch (IOException e) {
     }

I'm trying to write a method to open a .doc file and
display the text to screen, the program runs but
nothing appears on the screen. Is the code below the
correct way or is it flawed.
class Open implements ActionListener
          public void actionPerformed(ActionEvent event)
               try {
               JTextPane view = app.setScreen();
BufferedReader in = new BufferedReader(new
w FileReader("outfilename.doc"));
     String str;
     while ((str = in.readLine()) != null) {
     view.setText(str);     
in.close();
atch (IOException e) {
Hard to tell why you aren't getting any output without more of the program.
One thing I see is that this classes replaces the text of JTextPane with the last string read from the file. If the last string were a blank line then you would have nothing to show.
If you are assuming this is a reasonable size document then you might consider appending each line read into as StringBuffer then set the text of the JTextPane to the contents of the StringBuffer after the reaches then end.

Similar Messages

  • Flash CS5 ِAn error occurred opening file and WinRar The archive is either in unknown format or damaged

    I have fla files and when I opened by flash cs5 11.5.1 it says "An error occurred opening file". I tried sure to make it rar or zip and repair it. When I opened by WinRar it says "The archive is either in unknown format or damaged"
    Please Please Please Help ME !!!!! .. I have been done a lot of work on it .. I am so tired .. Please Help Me Please
    Thank you so much

    do you have a working swf?
    if so, you can decompile it and recover some or all your work.
    if not, are you able to rename the fla to a rar and then unrar it?

  • Read a text file and put the text in a TextEdit UI

    I have found code sample for reading file inside webdynpro, but I can't manage to make it works with a text file on the web (ex.: "http:/.../file.txt").
    Can someone post the exact code needed for that?
    Thanks!

    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());

  • Importing log4j.xml and viewing the out put .

    hi iam having log4j.xml which i should use to view the output .iam using netbeans IDE .i imported import org.apache.log4j.Logger; then i added log4j.xml in source package .and apache log4j to the libraries .
    *.but how to import this log4j.xml file and view the output?*
    import java.util.logging.Level;
    import org.apache.log4j.Logger;
    static Logger logger = Logger.getLogger( Header.class);the how to use * logger* to view ConsoleAppender and PatternLayout

    Open a text editor. Go to the File menu and select the Open option. Navigate to the directory where the log4j.xml file is located. Select it and it will appear in your text editor, where you will be able to view it.
    That wasn't what you meant, was it? Unfortunately I can't understand what you do mean. You seem to be confusing the act of writing a program which will write output to a file with the act of looking at that file. And you seem to be confusing Java programming operations ("import") with something else that I don't understand.
    Could you rephrase your question and perhaps include something that explains what you want to do? Because you have it backwards. Loggers don't view files, viewing is reading. Loggers write files.

  • Executing a native process and getting the text output

    Hi,
    I have the following problem.
    When I execute a native DOS process (lets say a batch file), and
    expect some text output from this process I use the following code:
    String command = "test.bat";
    Process process = runtime.exec(command);
    BufferedReader rd = new BufferedReader(new InputStreamReader(process.getInputStream()));
    String s = new String();
    while((s = rd.readLine())!=null) {
         out.println(s + "<br/>" );
    The problem is that as long as rd.readLine() does not return null, the page does not display the result. When the process crash, sometimes nothing return.
    I would like to display the output as it comes, i.e. line by line.
    I have no clue on how to do that except writting the output in a text file, and reading the text file with a page that reload every x seconds.
    I do not beleive this is a good solution.
    Additionaly, I may have a huge output. It seems to make the process
    to hang. Is there a was to fix it.
    Could someone give me some hints.
    Regards,
    Arnaud.

    I am having the same problem...did you ever solve it?

  • How can I prevent a PDF file from being copied, printed or downloaded? Students should only be able to view the text and and not distribute it in any way.

    How can I prevent a PDF file from being copied, printed or downloaded? Students should only be able to view the text and and not distribute it in any way.

    You can prevent it from being printed by applying a security policy to it
    in Acrobat. The rest can't be prevented, unless you spend  a LOT of money
    on DRM protection.

  • I get a dialogue box asking "What should Firefox do with this file" Options open with or save file. My wife selected save file and now it only opens note pad and displays the text of the file to be saved. OK in windows Internet Explorer.

    I get a dialogue box asking "What should Firefox do with this file" Options open with or save file. My wife selected save file and now it only opens note pad and displays the text of the file to be saved. OK in windows Internet Explorer.

    P.S. Site is http://www.coldwatercreek.com

  • How can i convert 2k resolution dpx files of a movie to DCP and will they be able to open the harddisk and view the files?

    how can i convert 2k resolution dpx files of a movie to DCP and will they be able to open the harddisk and view the files?

    AFAIK, this is beyond the capabilities of FCPX/Compressor. This company makes a plug-in, which I have to say I have no experience with. Here is a thread that may give you some other ideas. Good luck.
    Russ

  • Open a url and view the files with it's timestamp

    Hi guys,
    I need to create a flow service in SAP BC to connect to a server by it's url and display it's files with it's timestamps.
    I have never done this b4, and usinf SAP BC makes it harder for me.. Mostly I need to know how to access the server and view the files with their timestamp.
    Any guidance for me will be much appreciated.
    Thank u.

    Yes,
    It's like this. I will connect to an FTP server. Then I need to view the files it the server or folder i specify with their respective timestamps.
    I am using SAP BC and it's webMethods to create the JAVA flow service. I am only now familiarising myself with SAP BC.
    Moreover I have never done a coding to access a server and list it's file. I can do it o view in a local directory using JFrame aand stuff... But SAP BC doesn't support those..
    So If u can give me some guidelines to follow.. i would appreciate it.
    Here's what i have come up with so far
    public static final void ReadFileServer( IData pipeline ) throws ServiceException
    //define input variables
         IDataCursor idcPipeline = pipeline.getCursor();
         String path = null;
         path = (String)idcPipeline.getValue();
         // Check if url is in the pipeline
         if (idcPipeline.first("path"))
              File dir = new File(path);
              String filesFound[]=dir.list();
              long [] age;
              age = new long[filesFound.length];
              for (int i = 0; i < filesFound.length; i++)
                   age = new File(filesFound).lastModified();
              String temp = "";
              for (int i = 0; i < age.length - 1; i++)
                   for(int k = i+1; k < age.length ; k++)
                        if (age > age [k])
                        temp = filesFound;
                        filesFound = filesFound[k];
                        filesFound[k] = temp;
              for (int i = 0; i < filesFound.length; i++)
              //get url out of the pipeline
              path = (String)idcPipeline.getValue();
              //insert the FILES into the pipeline
              idcPipeline.insertAfter("filesFound", filesFound);
              idcPipeline.insertAfter("age", age);
         //If it is not in the pipeline ERROR
         else
         age = "False";
         idcPipeline.insertAfter("path", path);
         //insert the successFlag into the pipeline
         idcPipeline.insertAfter("age", age);
         //Always destroy cursors that you created
         idcPipeline.destroy();
    return;
    }

  • What are the best tools for opening very large XML files and examining the tree and confirming they are valid?

    I am generating some very large XML files (600,000+ lines, 50MB+ characters). I finally have them all being valid XML and valid UTF-8.
    But the files are so large Safari and Chrome will often not open them. FireFox will though.
    Instead of these browsers, I was wondering if there are there any other recommended apps for the Mac for opening and viewing the XML, getting an error message if they are not valid for some reason and examing the XML tree?
    I opened the file in the default app for XML which is Xcode, but that is just like opening it in a plain text editor. You can't expand/collapse the XML tree like you can with a browser, and it doesn't report errors.
    Thanks,
    Doug

    Hi Tom,
    I had not seen that list. I'll look it over.
    I'm also in touch with the developer of BBEdit (they are quite responsive) and they are willing to look at the file in question and see why it is not reporting UTF-8 errors while Chrome is.
    For now I have all the invalid characters quashed and things are working. But it would be useful in the future.
    By the by, some of those editors are quite pricey!
    doug

  • How to make the Open/Save dialogue download the text file instead of JSP

    I am currently coding on a JSP program, which searches the database and writes the resultset into a file on the server, and then allows the client to download this tab delimited text file onto their local machine. But I met a problem, when the default Open or Save dialogue appears, it shows that it's trying to download the running JSP file from my local host instead of the newly-created text file. Despite this, when I click OK to either Open or Save the file, a warning dialogue will appear saying: The explorer cann't download this file, it's unable to find this internet site or something like that. I get no error message from the server but I was always told that Javax.servlet.ServletException: getWriter() was already called. What does this mean?
    I guess maybe this is caused by the mix use of outputStreams in my program. I don't know if there is a way to directly read the resultset from the database and then send it through outputStream to the client. My solution is: first create a file on the server to hold the resultset, and then output this file to the client. I did all these in one JSP program: Create file on the server, search database, and then read file and output the contents to client. Is this correct? I attached my code, please feel free to correct any of my mistake? Thanks!
    //global.class is a class dealing with database connection
    <%@ page language="java" import="java.sql.*,java.util.*,java.math.*,java.io.*,ises.*,frmselection.*" %>
    <jsp:useBean id="global" scope="session" class="ises.Global" />
    />
    <!--start to process data-->
    <%
    //get query statement from the session
    String sQuery = "";
    if (session.getAttribute("sQuery")!=null && !(session.getAttribute("sQuery").toString()).equals(""))
    sQuery = session.getAttribute("sQuery").toString();
    String path = "c:/temp";
    String fileName = "temp.TXT";
    File file= null;
    FileOutputStream fo = null;
    PrintStream ps = null;
    try {
         file = new File(path,fileName);
         if(file.exists()) {
         file.delete();
         file.createNewFile();
         fo = new FileOutputStream(file);
         ps = new PrintStream(fo);
    }catch(IOException exp){
         System.out.println("IO Exception: " +exp.toString() );
    java.sql.ResultSet recResults     = null;
    java.sql.Statement STrecResults = null;
    STrecResults = global.getConnection().createStatement();
    recResults = STrecResults.executeQuery(sQuery);
    ResultSetMetaData meta = recResults.getMetaData();
    int columns = meta.getColumnCount();
    String [] tempColumnName = new String[columns];
    String [] ColumnName =null;
    int DisColumns = 0;
    int unDisCol = 0;
    String sLine = "";
    if(recResults.next()) {     //if_1
    for(int n=0;n<columns;n++) {
    String temp = meta.getColumnName(n+1);
    if(!temp.equals("PROJECTID")&&!temp.equals("BUILDINGID")&&!temp.equals("HAZMATPROFILEID")) {
    sLine = sLine + "'" + temp + "'" + " ";
    tempColumnName[DisColumns] = temp;
    DisColumns ++;
    ColumnName = new String[DisColumns];
    }else {
    unDisCol ++;
    }//end for
    for(int i=0;i<(columns-unDisCol);i++) {
    ColumnName[i] = tempColumnName;
    ps.println(sLine);
    do{
    sLine = "";
    for(int n=0;n<(columns-unDisCol);n++) {
    String tempColName = recResults.getString(ColumnName[n]);
    if(tempColName==null) {
    sLine = sLine + "" + " ";
    } else {
         sLine = sLine + "'"+tempColName+"'" + " ";
    ps.println(sLine);
    }while(recResults.next());
    }     //end if_1
    recResults.close();
    recResults = null;
    STrecResults.close();
    STrecResults = null;
    %>
    <!--end of processing data-->
    <!--start of download.jsp-->
    <%
    //set the content type to text
    response.setContentType ("plain/text");
    //set the header and also the Name by which user will be prompted to save
    response.setHeader ("Content-Disposition", "attachment;filename=temp.TXT");
    //Open an input stream to the file and post the file contents thru the servlet output stream to the client
    InputStream in = new FileInputStream(file);
    ServletOutputStream outs = response.getOutputStream();
    int bit = 256;
    try {
         while ((bit) >= 0) {
         bit = in.read();
    outs.write(bit);
    } catch (IOException ioe) {
    ioe.printStackTrace(System.out);
    outs.flush();
    outs.close();
    in.close();     
    %>
    <!--end of download -->

    Thanks. I believe something wrong with this statement
    in my program:
    You are correct there is something wrong with this statement. Seeing how you are doing this in a jsp, not really what they're made for but thats another topic, the output stream has already been called. When a jsp gets compiled it creates a few implicit objects, one of them being the outputstream out, and it does this by calling the response.getWriter(). getWriter or getOutputStream can only be called once, other wise you will get the exception you are experiencing. This is for both methods as well, seeing how the jsp compiles and calls getWriter means that you cannot call getOutputStream. Calling one makes the other throw the exception if called as well. As far as the filename problem in the browser goes I'm guessing that it's in IE. I've had some problems before when I had to send files to the browser through a servlet and remember having to set an inline attribute of some sort in the content-dis header inorder to get IE to see the real filename. The best way to solve this is to get the orielly file package and use that. It is very easy to use and understand and does all of this for you already. Plus it's free. Cant beat that.
    ServletOutputStream outs =
    response.getOutputStream();
    because I put a lot of printout statement within my
    code, and the program stops to print out exactly
    before the above statement. And then I get the
    following message, which repeats several times:
    ServletExec: caught exception -
    javax.servlet.ServletException: getWriter() was
    already called.

  • I have a PDF with a diagram, I need to translate the text so I open it in Illustrator.  The document opnes up vertically oriented  I try to put it horizontal to be able to read and change the text  However everything I have done is not working  The artboa

    I have a PDF with a diagram, I need to translate the text so I open it in Illustrator.  The document opens up vertically oriented  I try to put it horizontal to be able to read and change the text  However everything I have done is not working  The artboard does change, but the diagram stays vertical.....Please help  I need to finish that for today..Please help

    A PDF usually consists of one to an indefinite number of clipping masks inside each other.
    You need to be very carefull with selecting stuff.
    So you need to read the manual on how to select stuff and on the basics of Illustrator.
    On top of that: because of the complex hierarchy of PDF files, it is kind of difficult to help you without seeing anything.

  • I have downloaded video in MP4 from my GoPro camera, but I cannot open and view the video.  Help please.

    I have downloaded video from my GoPro helmet camera to my iPad 1 photos, but i cannot open and view the MP4 file.  Please help.

    Yeah, just as said above, you need to convert it to iPad supported video formats first and then sync it back to the iPad.
    Chek the iPad Supported Video and Audio Formats first.

  • Font not found when opening file and not able to resolve, but is listed in the fonts drop down list?

    Hi, i just downloaded some files from a friend and he sent me a link to download the fonts. I did so and 98% of the fonts work, but there are two fonts i am struggling with.
    When i open the file i get the font missing warning and it asks me to resolve the fonts. I cannot find the appropriate font in the drop down list so i click 'don't resolve' and start to edit the file. i then come across some text that has missing fonts and i am able to highlight the text and change the text to the appropriate font using the type tool and the font I am looking for is in the drop down list.
    The fonts that aren't working are:
    Franchise Bold and BebasNeue
    The problem is there are multiple separate incidents where these fonts occur, and going through changing each one manually would take a lot of time.
    Is there something i can do to fix them all at once?
    Thanks,
    Harry

    I do not see either font  in the list you show.  I see Bebas Neue xxx but no Bebas Neue without any extra style. Try Bebas Neue at Download Bebas Neue Font - Thousands of fonts to download for free

  • Ive gotten a zip file and i have no idea how to open it and view images

    ive gotten a zip file and i have no idea how to open it and view images?

    Double-click it in the Finder.
    (107691)

Maybe you are looking for

  • Music appears to be on ipod when viewing in iTunes but isn't there

    I have a new problem with my previously reliable iPods. When I connect them to my computer and either manually or automatically sync music to them, the sync appears to work fine, and I can click on a song and play it from iTunes. But when I disconnec

  • How to delete streamed songs in iPhone?

    I listen to songs via streaming from iCloud. When flying I want to listen to records I choose to have with me. When i turn of "show all music" in Music preferences to find my manually loaded records, following happens: There are so many songs left fr

  • Why is my shipping taking so long?

    i ordered my macbook pro 15 inch 2.2 gig for college about 2 weeks ago and have seen nothing about the product being shipped, i called up my college's book store where i ordered the computer and asked them what the problem was, to which i was told th

  • Message "The required index.xml file is missing."

    I updated my OS a couple of weeks ago.  Ever since then I receive the following message whenever I try to open a Pages document:  The required index.xml file is missing.  I first got this message when trying to open something sent from my iPad, that

  • CS6 OFFICAL ADOBE COMMENT ON UPDATE 13.0.2

    abobe teq support worked on my macbook retina for 3-4 hours and after every attempt to update to this update i was told he contacted the photoshop team and update 13.0.2 is only for photoshop not the extended version. im wondering if this is true or