How to open/read file using Java in Unix?

Hi Friends,
Can you please help me out how to open/read file using java in unix os? I have create one text file in "/home/test.txt" in unix environment. How to open the same file & read using java code?
- Hiren Modi

http://java.sun.com/docs/books/tutorial/essential/io/index.html

Similar Messages

  • How to print PDF files using java print API

    Hi,
    I was goign throw lot of discusion and reading lot of forums related to print pdf files using java api. but nothing seems to be working for me. Can any one tell me how to print pdf files using java api.
    Thanks in advance

    Mike,
    Can't seem to get hold of the example described in your reply below. If you could let us have the URL to get then it would be great.
    My GUI application creates a pdf document which I need to print. I want to achieve this using the standard Java class PrinterJob (no 3rd party APIs I'm afraid, commercial restraints etc ..). I had a stab at it using the following code. When executed I get the pretty printer dialog then when I click ok to print, nothing happens!
    boolean showPrintDialog=true;
    PrinterJob printJob = PrinterJob.getPrinterJob ();
    printJob.setJobName ("Contract.pdf");
    try {
    if (showPrintDialog) {
    if (printJob.printDialog()) {
    printJob.print();
    else
    printJob.print ();
    } catch (Exception PrintException) {
                   PrintException.printStackTrace();
    Thank you and a happy new year.
    Cheers,
    Chris

  • How to uncompress zip files using java program

    hai,
    please give some sample code to decompress the zip file.
    how to uncompress zip files using java program
    thanking you
    arivarasu

    http://developer.java.sun.com/developer/technicalArticles/Programming/PerfTuning/
    Scroll down to 'Compression'

  • How to run .jar on linux & how to create .jar file using java?

    hi, may i know how to run .jar on linux & how to create .jar file using java? Can u provide the steps on doing it.
    thanks in advance.

    Look at the manual page for jar:
    # man jar
    Also you can run them by doing:
    # java -jar Prog.jar

  • How to open a file using OAF

    Hi,
    I want to open a file using OAF. I know the path and file name.
    How can I open it, if file is in UNIX or in windows, where ever.
    Is there any way to do that.
    Thanks in Advance!!

    Hi Ankur,
    I had something link this requirement, that also for a concurrent program output only, but the output was txt file, and make it a zip file and give a dynamic link and open it.
    For that i used the following code, may be it will help.
    String zipout = pageContext.getParameter("ZIPOUT");
    if(zipout!=null && zipout.equals("Y"))
    try
    DataObject sessionDictionary = (DataObject) pageContext.getNamedDataObject("_SessionParameters");
    HttpServletResponse response = (HttpServletResponse) sessionDictionary.selectValue(null, "HttpServletResponse");
    HttpServletRequest request = (HttpServletRequest) sessionDictionary.selectValue(null, "HttpServletRequest");
    String requestID = pageContext.getParameter("REQUESTID");
    response.setHeader("Content-Disposition","p; filename=CatExtract"+requestID+".zip");
    response.setContentType("application/x-zip-compressed");
    ZipOutputStream zip = new ZipOutputStream(response.getOutputStream());
    try
    byte[] buffer = new byte[1024];
    int bytesRead;
    //to get the value of output directory
    String fileName = "/o"+requestID+".out";
    Serializable[] parameters = { requestID };
    //Get the output URL for this requests output.
    pageContext.getApplicationModule(webBean).invokeMethod("getOutputURL", parameters);
    String outputURL = (String)pageContext.getTransactionValue("OutputURL");
    pageContext.writeDiagnostics(this.getClass().getName(),"outputURL in the xxt CO"+outputURL,1);
    try
    URL fileURL = new URL(outputURL);
    URLConnection urlConn = fileURL.openConnection();
    DataInputStream out = new DataInputStream(urlConn.getInputStream());
    try
    ZipEntry entry = new ZipEntry(fileName);
    zip.putNextEntry(entry);
    while ((bytesRead = out.read(buffer)) != -1)
    zip.write(buffer, 0, bytesRead);
    zip.closeEntry();
    pageContext.writeDiagnostics(entry.getName(), " added.",1);
    catch (Exception ex)
    pageContext.writeDiagnostics(this.getClass().getName(),"Exception 113"+ex,1);
    finally
    out.close();
    catch (IOException ex)
    pageContext.writeDiagnostics(this.getClass().getName(),"Exception 124"+ex,1);
    System.out.println("Exception 124 "+ex);
    Thanks.
    With Regards,
    Kali.

  • How to open specific port using java program

    Hello,
    I want to open ,close port using java comm.plz help me how can i do it.is it possible
    by using java program.later i want to use that specific port to accept the server socket connection .plz
    help me.

    i try this java program.*but it get block in accept method*.tht mean i m not able to make connection with port.
    import java.sql.SQLException;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    class MakeConn
         public final static int PORT = 7788;
    public static java.net.Socket clientSocket = null;
    public static java.io.PrintWriter pw = null; // socket output stream
    public static java.io.BufferedReader br = null;
    public static ServerSocket server_socket;
         public static void main(String[] args) throws SQLException
         try {
              server_socket = new ServerSocket(PORT);
    clientSocket = server_socket.accept();
    System.out.println("CLIENT>>>" + clientSocket);
         br = new java.io.BufferedReader(new java.io.InputStreamReader(clientSocket.getInputStream()));
    pw = new java.io.PrintWriter(clientSocket.getOutputStream(), true);
    String message = br.readLine().trim();
    System.out.println("message is"+message);
    pw.close(); // close everything
    br.close();
    clientSocket.close();
         catch (Exception ex) {
    ex.printStackTrace();
    }

  • How to load avi files using java ?

    Hi, i need to load avi (movie file) using java. I have usually done with java applet, but the applet just can load image (jpeg, gif)

    All types of data should be downloaded in same way. What is your problem: exception or something else? Post here.

  • How to gzip a file using java

    Friends,
    I want to gzip a file in unix using my java program, can I use Runtime.exec() method and run the gzip command to achieve this ?
    Is there any other way to zip/compress a file using java api ?
    Thanks

    Use [url http://java.sun.com/j2se/1.5.0/docs/api/java/util/zip/GZIPOutputStream.html]java.util.zip.GZIPOutputStream along with [url http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileOutputStream.html]java.io.FileOutputStream

  • Open a file using java......... how?

    hi all
    I have a prob with my code
    the problem is by using the FileChooser like
    file = fileChooser.getSelectedFile();
    I have the file name but how can i open that file e.g. if file is word document then that file should open in word , if that file is HTML file then open in IE , and other files as well.
    is there any way to open a file
    plz help me
    Thanx
    Regards
    Satinderjit

    veer ji, try this code on your pc if you can. Click the print button and see that happens. thanx yuvraj:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.*;
    //import com.sun.java.swing.*;
    import javax.swing.*;
    public class ComponentPrinterFrame
    extends JFrame
    implements Printable {
    public static void main(String[] args) {
    ComponentPrinterFrame cpf = new ComponentPrinterFrame();
    cpf.setVisible(true);
    public ComponentPrinterFrame() {
    super("ComponentPrinterFrame v1.0");
    createUI();
    protected void createUI() {
    JPanel panel = new JPanel();
    JButton printButton = new JButton("Print");
    panel.add(printButton);
    panel.add(new JList(new Object[] { "One", "Two", "Three" }));
    panel.add(new JButton("Push me"));
    panel.add(new JCheckBox("Chess", true));
    panel.add(new JComboBox(new Object[] { "Eins", "Zwei", "Drei" }));
    printButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    PrinterJob pj = PrinterJob.getPrinterJob();
    pj.setPrintable(ComponentPrinterFrame.this);
    if (pj.printDialog()) {
    try { pj.print(); }
    catch (PrinterException pe) {
    System.out.println(pe);
    setContentPane(panel);
    setSize(400, 400);
    // Center.
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = getSize();
    int x = (screenSize.width - frameSize.width) / 2;
    int y = (screenSize.height - frameSize.height) / 2;
    setLocation(x, y);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    dispose();
    System.exit(0);
    public int print(Graphics g, PageFormat pf, int pageIndex) {
    if (pageIndex != 0) return NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2D)g;
    g2.translate(pf.getImageableX(), pf.getImageableY());
    getContentPane().paint(g2);
    return PAGE_EXISTS;

  • How can we open any file using JAVA...

    Hi all
    i trying to make code in that code i choose a file using a filechooser then put that file name in FILE object like (File file = fileChooser.getSelectedFile();)
    but the thing is how can i open that file for example if that file is HTML file then opens in IE or if that file is MS Word document that open in Word, like that
    is there any suggestions
    Thanx
    Regards
    Satinderjit

    start is a windows command-line utility.
    start foo.doc will start Word (or Star Office or Word Perfect or whatever is registered for the .doc extension),
    start bar.htmnl will start your registered browser etc.

  • How to open Word Document using java?

    Respected Sir/ Madam,
    I am doing my project in Network Security using java. I have to transfer the files from server to the client. Each transferred file should have some of the access privileges such as read, write and exeucte. If the transferred file is a word document means then automatically the client should open Microsoft word and if the file is having Read Permission alone then the save, Save As, cut,copy, paste options in the MS - Word should be disabled. This is similar for all the files that i have transferred. That is if the transferred file is excel, audio, video,txt file the corresponding application should be opened properly. How could I acheive this. If the file is having write permission then if the user clicks the save option then the contents of the file should be saved in the server machine not in the client machine, Could we achieve this???? Can anyone help me regarding this? Please give me your views about this query?

    Respected Sir / Madam,
    Thank you very much for your reply. Could we use Microsoft API inside java program to achieve my doubts?? Could U explain it more????

  • Error trying to open a file using java.io.* in an Applet

    I have a file called wordlist.txt and I am using java.io.* to open it. When I try it
    in Applet Viewer it runs without a hitch. But when I try to run it in a
    browser as an Applet, it errors out saying:
    com.ms.security.SecurityExceptionEx[package3/SpellCheck.setWordList]: cannot access file wordlist.txt
    I have tried adding this file to my Project and accessing it that way but I still get
    the same message. If anyone can help with this, I sure would appreciate it.
    My code is as follows:
    String inWord = new String("zzz");
    try {
    File myWordList = new File("wordlist.txt");
    BufferedReader inWordList = new BufferedReader(
    new FileReader(myWordList));
    inWord = inWordList.readLine();
    while (inWord != null) {
    wordList.addElement(inWord);
    inWord = inWordList.readLine();
    } // end while
    inWordList.close();
    } // end try
    catch (Exception e1) {
    // Pr is equivalent System.out.println();
    Pr("Error Reading this line " + '\n' + inWord + '\n' + e1);
    } // end catch
    } // end setWordList()

    Applets are generally prevented from reading as well as writing files, but appletviewer can load files from the hard drive, so, that is the cause of the behaviour you have observed. To know more about enabling applets load files, you have to sign your applets,
    learn more at
    http://java.sun.com/sfaq/#prevent

  • How to upload a file using java bean?

    hi,
    i need a code simple how to upload a file from jsp form to a java bean file (not a servlet)
    thank,s zik

    Hi,
    i need a code sample how to upload a file from jsp
    form to a java bean file (not a servlet)You can use jspSmartUpload component which is a free, fully-featured JSP component.
    jspSmartUpload provides you with all the upload/download features you could possibly wish for :
    * Simple and complete upload
    * Total control over the upload process
    * �Mixed forms� management
    * Total control over files sent
    * Download whatever you want
    For further information about jspSmartUpload please visit
    http://www.jspsmart.com/
    Hope this helps.
    Good Luck.
    Gayam.Srinivasa Reddy
    Developer Technical Support
    Sun Micro Sysytems
    http://www.sun.com/developers/support/

  • How to download video files using java

    hi,
    i am designing a download manager using java. Although i am able to download html pages and images as of now, i am facing problems while downloading the video files. Can somebody please guide me as to how to do this.
    Thanks in advance,
    Arun

    All types of data should be downloaded in same way. What is your problem: exception or something else? Post here.

  • How to hide hidden files using java FileSystemView

    My application has a browser. I use the following method from FileSystemView
    public File[] getFiles(File dir,
    boolean useFileHiding)
    with false as the second argument so that the browser doesn't display hidden files.
    It doesn't work completely.
    I found out there are two types of hidden files in Mac. the ones that being with "." (unix based) and the ones that have an invisibility attribute for the meta of the file (folders like /usr, /bin, /tmp, /etc).
    The getFiles filter works only for hidden files that start with "." but it still shows the second type of hidden files.
    For the second type of hidden files in Mac, how can I get the invisibility file attribute information in Java so that I can hide them from the file browser?
    thanks,

    The GetFileInfo tool that ships with the XCode Tools can display the file's information. Additionally, the SetFile tool allows setting those flags. How you use java to implement those, I suggest you ask at the Unix forum under OS X Technologies.

Maybe you are looking for

  • Error in creating Transport Request for a view table

    Hello all, I have an ECC IDES 6.0 system named EC1 and another one which is ECC EhP4 IDES named EA1 which I have just installed. One of my requesters has a view table named ZVAITM_TBLE in EC1 and she wants it to be transported to EA1. So I created a

  • How do I turn off pop up blockers on my ipad2?

    How. Do o turn off pop up blockers on my iPad 2?

  • Show file size coming from UCM

    I need to show the size of a file that comes from Oracle UCM and the file size should be shown in Kilobytes, the file size is in bytes so I've divided in 1024 for the number in kilobytes I have the following source code and the continuous result bein

  • DBMS_SPACE(9i) for tablespace growth trend..?

    Hello, for 10G, dbms_space.object_growth_trend() can expect table's growth.... for 9i (9.2.0.6 in Sun9) database, is there any friend has experience know how to do for the following purpose: 1. How to expect tablespace growth? say, to accommodate new

  • How to run query in parallel  to improve performance

    I am using ALDSP2.5, My data tables are split to 12 ways, based on hash of a particular column name. I have a query to get a piece of data I am looking for. However, this data is split across the 12 tables. So, even though my query is the same, I nee