How to open a text file without using dialog box

I can open a file using dialog box but I want to open a file without using any dialog box for writing.
With the following commands a new file is created.
File outputFile = new File("outagain.txt");
FileWriter out = new FileWriter(outputFile);
I want to open an existing file and put some more text in it using FileWriter or any other object
rgds,
Arsalan

import java.io.*;
class UReader
    BufferedReader in;
    BufferedReader input;
    String fileName;
    public UReader(String fileName)
        this.fileName = null;
        this.fileName = fileName;
        try
            in = new BufferedReader(new FileReader(fileName));
            input = new BufferedReader(new FileReader("A.b"));
        catch(IOException _ex) { }
    public final String getContent()
        String txt = "";
        try
            while(in.ready())
                txt = txt + in.readLine();
                txt = txt + "\n";
            in.close();
            txt.trim();
        catch(IOException _ex) { }
        return txt;
    public final String getLine(int row)
        try
            input = new BufferedReader(new FileReader(fileName));
        catch(IOException _ex) { }
        String txt = null;
        if(row <= getRows()) {
            try
                for(int i = 0; i < row; i++)
                    txt = input.readLine();
                input.close();
            catch(IOException _ex) { }
        } else {
            txt = "Index out of Bounds";
        return txt;
    public final int getRows()
        try
            input = new BufferedReader(new FileReader(fileName));
        catch(IOException _ex) { }
        String txt = null;
        int rows = 0;
        try
            while(input.ready())
                txt = input.readLine();
                rows++;
            input.close();
        catch(IOException _ex) { }
        return rows;
import java.io.*;
import java.util.*;
class UWriter
    PrintWriter out;
    String fileName;
    String[] txt;
    static int NEW_LINE = 1;
    static int APPEND = 0;
    public UWriter(String s)
        fileName = null;
        txt = null;
        fileName = s;
        try
            out = new PrintWriter(new BufferedWriter(new FileWriter(s, true)));
        catch(IOException ioexception) { }
    public final void addContent(String s, int i)
        int l = 0;
        StringBuffer sb = new StringBuffer(s);
        s.replaceAll("\n\n", "\n###\n");
        StringTokenizer str = new StringTokenizer(s, "\n");
        String token = null;
        while (str.hasMoreTokens()) {
            ++l;
            token = str.nextToken();
        str = new StringTokenizer(s, "\n");
        txt = new String[l];
        int k = 0;
        String test;
        while (str.hasMoreTokens()) {
            test = str.nextToken();
            if (test.equals("###")) test = "";
            txt[k++] = test;
        if(i == 0) {
            try
                for (int j = 0; j < txt.length; ++j) {
                    out.println(txt[j]);
                out.close();
            catch(Exception ioexception) { }
        } else {
            try
                out.println();
                for (int j = 0; j < txt.length; ++j) {
                    out.println(txt[j]);
                out.close();
            catch(Exception ioexception1) { }
    public final void writeContent(String s)
        int l = 0;
        s.replaceAll("\n\n", "###");
        StringTokenizer str = new StringTokenizer(s, "\n");
        String token = null;
        while (str.hasMoreTokens()) {
            ++l;
            token = str.nextToken();
        str = new StringTokenizer(s, "\n");
        txt = new String[l];
        int k = 0;
        String test;
        while (str.hasMoreTokens()) {
            test = str.nextToken();
            if (test.equals("###")) test = "";
            txt[k++] = test;
        try
            PrintWriter bufferedwriter = new PrintWriter(new BufferedWriter(new FileWriter(fileName, false)));
            for (int j = 0; j < txt.length; ++j) {
                bufferedwriter.println(txt[j]);
            bufferedwriter.close();
        catch(IOException ioexception) { }
}Maybe they are not the best codes, i wrote them a long time ago, so dont ask why i did anything wierd. :D
But anyway it works.

Similar Messages

  • How to open a text file

    hello
    if so have an idea on how to open a text file
    thanks

    File file=new File("[path to the text file]");
    String encoding="[encoding of the file]";
    BufferedReader reader=new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
    // Do whatever you like with the reader
    // For example write the text file to the output
    String line;
    while ((line=reader.readLine())!=null)
    System.out.println(line);
    reader.close();Hope it helps,
    Marcin
    PS. This is not the write forum category to post this question.

  • How do I ensure user name is shown rather than 'another user' on the 'File in Use' dialog box?

    How can I ensure user names are shown rather than just 'another user' on the 'File in Use' dialog box that appears when attempting to edit a checked out document in Microsoft Word/Excel? 
    All suggestions welcome. 

    If I recall correctly, that dialog is generated by the Office client product supporting that file type. There would be no way to modify it.
    Trevor Seward
    Follow or contact me at...
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • How to open a text file using button click event

    hi, How can i open a text file in a textpad or notepad on the click event of a button.?
    Thanks
    Jay

    Pnt,
    this will not work LV 8.0.1 and LV 8.6 will give back error 193.
    Attached is a VI to use the ShellExecute WinAPI. The VI is LV 7.1.1.
    Message Edited by waldemar.hersacher on 10-09-2008 10:48 PM
    Waldemar
    Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
    Don't forget to give Kudos to good answers and/or questions
    Attachments:
    ShellExecute.zip ‏27 KB

  • Urgent : How to upload a tif file without using upload element

    could someone please tell me how to upload a tif file(any file) without using upload element. Function Module GUI_UPLOAD does not work. Please suggest. Appreciate your suggestions.

    Hello Suri,
    there's currently no way to achieve this.
    Best regards,
    Thomas

  • How to get the update file without using Nokia Sof...

    The network connection is unreliable and downloading the firmware update using PC Suite for my Nokia E90 proves difficult. Does anyone know how I can get the firmware version 300.34.84?
    The trouble is Nokia's Software Updater does not accommodate any slight interruption to the connection during the update process. I will update this discussion with what version of PC Suite I have once I get that info.
    Any help is kindly appreciated

    In fact, it is not Possible to get the update file without using Nokia Software Updater or you should search the net to find the update files in another place and even you get them, you can not use them with NSU.
    You can Update your Device with:
    1 - NSU (Nokia Software Update)
    2 - FOTA (Firmware Over The Air) for FP2 devices ONLY.
    3 - Nokia Care Center
    there is not other way to upgrade.
    Hope useful for u.
    regards
    Nokia N79 4GB
    SW Version: 32.001 RM-348 MEA

  • Opening a pdf file without using ABAP

    Hi All,
        Can I open a pdf file in the ITS without using ABAP
        coding. I mean by using Java Script in an another
        dialog/page can i open a pdf file. If anyone has got
        any idea or sample code please let me know.
      Thanks,
       Amitabh

    Hi,
      Where exactly you want to open the file?
    The most simple way  would be to upload the file under MIMES and provide the URL in the corresponding ITS service.
    BR,
    Disha.
    Pls reward points for helpful answers.

  • How to open an InDesign file without .indd extension?

    Hi,
    I am trying to open an InDesign file which does not have the extension .indd.
    I can open the file from InDesign's File-> Open menu item. But if I try to open programmaticaly it says the file format is not supported.
    I tried using SDKLayoutHelper::OpenDocument and IDocumentCommands::CreateOpenCommand both gives the same error.
    Thanks,

    Thanks. My file was not proper. I am able to open the file without the extension.

  • How to print a text file contents using java.

    Using Input and Output streams I can add and retrive the contents to/from text file. But how to send this file contents to the printer or how to print the file.

    Example from my code:
       private void printErrorReport()
          PrintJob pjob = getToolkit().getPrintJob(m_frame,null,null);
          if (pjob != null) {
            Graphics pg = pjob.getGraphics();
            if (pg != null) {
              String s = detailsArea.getText();
              printLongString (pjob, pg, s);
              pg.dispose();
            pjob.end();
    // Utility method needed
       void printLongString (PrintJob pjob, Graphics pg, String s) {
         int pageNum = 1;
         int linesForThisPage = 0;
         int linesForThisJob = 0;
         // Note: String is immutable so won't change while printing.
         if (!(pg instanceof PrintGraphics)) {
           throw new IllegalArgumentException ("Graphics context not PrintGraphics");
         StringReader sr = new StringReader (s);
         LineNumberReader lnr = new LineNumberReader (sr);
         String nextLine = "       ";
         int pageHeight = pjob.getPageDimension().height;
         pageHeight -= 20;
         Font helv = new Font("Arial", Font.PLAIN, 12);
         //have to set the font to get any output
         pg.setFont (helv);
         FontMetrics fm = pg.getFontMetrics(helv);
         int fontHeight = fm.getHeight();
         int fontDescent = fm.getDescent();
         int curHeight = 0;
         try {
           do {
             nextLine = lnr.readLine();
             if (nextLine != null) {
               if ((curHeight + fontHeight) > pageHeight) {
                 // New Page
                 System.out.println ("" + linesForThisPage + " lines printed for page " + pageNum);
                 pageNum++;
                 linesForThisPage = 0;
                 pg.dispose();
                 pg = pjob.getGraphics();
                 if (pg != null) {
                   pg.setFont (helv);
                 curHeight = 0;
               curHeight += fontHeight;
               if (pg != null) {
                 pg.drawString (nextLine, 0, curHeight - fontDescent);
                 linesForThisPage++;
                 linesForThisJob++;
               } else {
                 System.out.println ("pg null");
           } while (nextLine != null);
         } catch (EOFException eof) {
           // Fine, ignore
         } catch (Throwable t) { // Anything else
           t.printStackTrace();
         System.out.println ("" + linesForThisPage + " lines printed for page " + pageNum);
         System.out.println ("pages printed: " + pageNum);
         System.out.println ("total lines printed: " + linesForThisJob);
         }

  • How to export to text file without ruin the format

    Hi guys,
    I need some help here. My company recently come with the decision to print the mainframe report file that usually come as a text file, to a virtual printer. This virtual printer is printing the report as Adobe PDF format. The problem is, my Line of Business have a macros on Excell file that will grab the information from the text file to be processed in the Excell format. I tried to use Adobe Professional 8 to re-convert the PDF file to be text file, but the result is, most of the blank space is gone, and it is align to left, thus make it unusable to the Excell file.
    Unfortunately, I can't provide you the sample of the document, because it contain classified customer info.
    But appreciate if you can give me some advice.
    Thanks and Regards.

    It sounds as if you are dealing with untagged PDF.
    Tagged output PDFs, with a well-formed structure, provide (amoung other things) the ability to Save As/Export
    content to some other applications with all or most of the layout/format intact.
    I suspect that the output PDFs you have are untagged.
    As there is, currently, a rather limited number of applications that support adequate tag management
    (FrameMaker, InDesign, MS Word (via Adobe's PDFMaker & to a much lesser extent with Office Save As to PDF - XPS)
    I suspect the mechanism used to provide your PDFs won't cut it with regards to providing a tagged output PDF having a
    well-fomed structure (which would include dictionaries containing format/layout data).
    As alluded to by Bernd, there may be third party plug-ins that might help.
    The more reliable/functional ones tend to not be inexpensive.
    Be well...

  • How to open a xsl files without going trhough downloading process on MAC OS

    I am able to open the same file in Safari but with Firefox, the document is automatically downloaded in xsl (it is a pdf) and I have to modify the extension in order to view it... very long...
    How can I modify my preferences so that this type of files are open directly by Firefox ?

    The Adobe PDF printer is no longer available in Snow Leopard. This is an announce to this fact at the entrance to the Acrobat Macintosh forum. The old methods for doing what you want will not work in Snow Leopard. I recommend you look at Quite Imposing. It can do everything you want and more. Alas, it comes at a price.

  • How to open a text-file with notepad from labview-vi?

    Hello,
    how can i execute a program from a vi?
    I want to open a textfile with Windows7-Notepad after selelecting it from a file-path-control and pressing an open-button.
    Thx for help
    Solved!
    Go to Solution.

    Use the command line.  Something like cmd /c notepad c:\temp\blah.txt should work.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to open Photoshop Temp File without extension

    Hi Adobe Community,
    My photoshop recently closed with some files open. I supect windows update to be behind that but can't be sure.
    I found in the %temp% folder couple files thats look interresting but no way to open them or be sure what it is.
    Files are:
         - Photoshop Temp21185767124 (36 864 KB)
         - Photoshop Temp745149862732 (1 164 672 KB)
         - Photoshop Temp1555241910196 (885 632 KB)
          - Photoshop Temp556628194484 (96 640KB)
         ... and there're 2 more at 0 KB.
    Using:
          - Photoshop CS5 12.1 x64
          - Windows 7 Service Pack 1
    Looking for a way to get those files back or at least know what they are...
    Thank you all
    Martin

    They're temporary scratch files that can be safely discarded.  There is nothing useful you can do with them.
    With Photoshop CS6 there may be auto-save recovery files as well nearby, but they're always .psb files, and you don't have to do anything special - Photoshop will automatically open them the next time you run it after a crash.  Photoshop CS5 did not have the auto-recovery feature; if it crashes you lose your work.
    -Noel

  • Since few days, Firefox crashes when trying to open local php files - without using localhost . It shoudn't. I tried to unsinstall everything and reinstall. But it didn't work. I use a mac osX 10..6

    I'm a beginner web developper. When I try to open php files, Firefox crashes and open millons of new firefox windows . I have no choice other than forcing Firefox to quit. When I use the localhost adress, it's Ok. But because I usually open the file directly from a folder in my HDD, (it's faster to dothis way) transforming it after with the localhost/~username/file ... it' s quite irritant.

    Hi.
    I tried logging in as a different user in the OS and that didn't work.
    Do you mean that Safari crashed there as well?
    If so, that's an indication that the startup disk needs repairing.
    Using Disk Utility to verify or repair disks

  • How to open adobe training files without winzip

    I am on a pc and my computer will not let me download any files from the tutorial videos on adobe online without first zipping them, and without these files I will not be able to figure out how to create a web browser page for the website

    I thought most Windows systems came pre-installed with WinZip -- a utility for unzipping compressed files.  If you don't have WinZip already, you can download StuffIt Expander (in my opinion, a better utility),  or 7-Zip.  Both are free.
    Nancy O.

Maybe you are looking for

  • Do we have anything similar to GP in ABAP?

    Hi Experts, I have to design an application in such a way that application guides the user step by step. This needs to be developed in the ABAP language. An approach which is similar to Guided Procedures in portal would be good. Do we have any simila

  • When browsing a Form PDF on my MAC is working but on my site it don't work

    Could you help me. It's so strange. I work in acrobat Pro and run the preview in acrobat and everything is ok. But when upload it to my site it don't work. The submit don't work and the required file does not scan.

  • Deleting an entry in an IDM Configuration Object

    Does anyone know of a way using Express or Express/Java to delete an entry in an IDM configuration object (not the configuration object itself)? For example, if an IDM Configuration object has a Hashmap with 6 entries and we want to delete entry numb

  • PanelGrid Border Formatting

    Hi guys, Well, I wanted to do some colspan's with h:panelGrid, but everything I read so far says that it isn't possible. So I'm forced into nesting panelGrids inside each other. That's fine. However, the borders are "doubling" ontop of each other. I

  • After installing Mountain Lion the battery indicator shows only 99% charge though charging for the whole night.

    Hi, I have been using MacBook Pro mid 2010 and recently I upgraded my OS from Snow Leopard to Mountain Lion. Since then whenever I charge my computer it stops charging at 99% but when I was using Snow Leopard it use to fully charge to 100%. Does inst