How to read a file in another location using Java ?

Hi all,
i suppose the below code reads my file 'ridata.dat' when it is in the same folder as my java class file.
How can i read it from a different location?
---------------------------------------------------------------FileRead.java---------------------------------------------------------------
import java.io.*;
class FileRead
public static void main(String args[])
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("ridata.dat");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
---------------------------------------------------------------FileRead.java---------------------------------------------------------------
Thanks in Advance,
Lakshma

Try with JFileChooser
               JFileChooser fileChooser = new JFileChooser();
               int returnValue = fileChooser.showOpenDialog(null);
               if (returnValue == JFileChooser.APPROVE_OPTION) {
                    File selectedFile = fileChooser.getSelectedFile();
                    System.out.println(selectedFile.getName());
               }Thanks,
Avin

Similar Messages

  • How to read multiple files at multiple locations using properties file

    hi all ,
    in my code i take configuration input from a properties file ,it was really easy but what if there are multiple files ? how can i take configuration input (file path etc) from properties file in that case ? any suggestion ?

    thanks :) ..i am doing like this :
    String fName[]=new String[10];
              String choice[]=new String[10];
              String Delim[]=new String[10];
              ResourceBundle a = ResourceBundle.getBundle("input");
              String n=a.getString("NOF");
              try
                   for(int i=0;i<Integer.parseInt(n);i++)
                        fName=a.getString("PATH"+(i+1));
                        choice[i]=a.getString("HEADER"+(i+1));
                        Delim[i]=a.getString("DELIMITER"+(i+1));
                        putData(fName[i],choice[i],Delim[i]);//to put data in database
              catch (NumberFormatException e)
                   System.out.println("Number of files are invalid");
    hope this method would be fine ....again thanks for the advice :) :)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How To read/write file on remote server in java

    Hi All,
    How To read/write file on remote server in java? I mean using URL - http://www.xyz.com can I right file to that perticular server.
    Thanks in advance

    If your server support a means of uploading files you can.
    A popular means is [http://en.wikipedia.org/wiki/WebDAV]
    However, by default web server don't allow you upload files, its usually something you need to configure or install.
    I suggest you have a look at your web servers documentation.

  • How to read a data from USB port using JAVA

    hi all,
    i need to know how to read a data from USB port using java. any API are available for java ?.........please give your valuable ideas !!!!!!!!!
    Advance Thanks!!

    You can do this. Please use this link
    [http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=uHu&q=java+read+data+from+usb+port&btnG=Search&meta=&aq=f&oq=]
    What research did you do of your own? Have you done some testing application and tried yourself??

  • How to launch Jar file in Mac Os using java code??

    can anyone tell me how can i launch another jar file in my apllication using java code.

    define "launch".
    - You want to run a new java program in a separate process? (see Runtime.exec())
    - You want to run a method in a specific class in the jar? (add jar to application classpath and then simply instantiate the class and call the method)

  • How to read multiple files of different name using single file adapter

    There are two inbound locations inbound1 and inbound2 , and the files structure present in these two inbound locations are same but the files start with different names example
    (1)files in inbound1 starts with file1,file2...
    (2)files in inbound2 starts with abc1,abc2...
    by using same file adapter with read option how can i read both files....

    Hi K.A.N.N.,
    You can define multiple directories using the above link in 11g and poll for the file as \*.*.
    Alternatively you can use the Synchronous Read and specify the file name at runtime.
    You can also use Pick activity to define multiple branches each with a File Adapter to read from a specified location with specified file name. Although it would contain multiple Adapter Definitions at Development-time, only one of the Adapters will execute at Run-Time.
    Regards,
    Neeraj Sehgal

  • How to read a file content in a ordinary java program

    Please help me is there is any method is available to read the content of the file.I am asking in pure java not in the servlets.Guys please help me.I got structed here

    Reading a text file in the systems character encoding: use the class java.io.FileReader. You can wrap a BufferedReader around it to get better performance (and a simple way to read lines)
    Reading a text file in another character encoding: use FileInputStream and convert it to a reader with:
    InputStreamReader reader = new InputStreamReader(fileStream, encoding);
    where encoding is the character encoding as a String (like "Cp850" or "UTF-16LE"). Again, you can wrap a BufferedReader around that reader.
    Reading a binary file: open a FileInputStream to the file and just read the bytes from it. You can use BufferedInputStream for better performance and DataInputStream to get a simple way to read primitive types like double and char.
    Please help me is there is any method is available to
    read the content of the file.I am asking in pure java
    not in the servlets.Guys please help me.I got structed
    hereAren't servlets pure Java?

  • How to read DefaultTrace files, What are other useful trace files

    Hi,
    I was trying to debug some issue using Default Trace file and it is painful. Can anyone point out some tips and tricks to do debugging. And how to read Default Trace file.
    Also what are the other useful trace files available? Please point out.
    Thanks,
    Deepak

    Hello Deepak,
    Here is the link with all infos how to use Log Viewer to view logfiles:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/57/5f1140d72dc442e10000000a1550b0/frameset.htm
    As all program generated logs are written to Default Trace file, it is the only file to check for  logs.
    Greetings,
    Praveen Gudapati
    p.s. Points are always welcome for helpful answers
    Message was edited:
    You can perform the following activities using the Log Viewer UI:
    &#9679;     Connect to and view logs on multiple servers
    &#9679;     Add log files
    &#9679;     Add log files from a log directory
    &#9679;     Customize the columns for the log records that are displayed
    &#9679;     Search for log records that meet specific criteria
    &#9679;     Filter log records by specific criteria
    &#9679;     Sort log records
    &#9679;     Merge log files within and across servers
    &#9679;     Use the refresh function to display the latest logs
    &#9679;     Open archives of log files
    &#9679;     Save log files to comma separated value (CSV) files and open them using Microsoft Excel.

  • How to read the hard disk serial number using java this is urgent

    Please do let me know any knows how to read the hard disk unique number provided by manufactruer using java library

    I don't know; I think the fate of the free worldrests upon the answer.
    Well, as long as the non-free world stays unharmed,
    it can't be so bad ...I think the "Axis of Evil" constitutes a group of countries that are just "misunderstood".

  • How to read ZIP files(having PDFs,Image) using MQ Series link for R/3

    Hi,
    1)Is it possible to transfer a zip file (having an image or pdf) using IDocs in SAP 4.6C using MQ Series link for R/?
    Scenario: "MQ Series link for R/3" converts Business-Reports from a third-party software,into SAP IDocs.Each Business-Report contains one XML file and one ZIP file.
    2)Being on ABAP side,do I have to worry about how the zip file would be converted into IDocs?
    Detailed descrption:
    This scenario requires integration of a non-SAP software which talks in XML with SAP R/3(4.6C).The customer has decided to go with 'MQ Series link for R/3' (which integrates any non-SAP application running on IBM MQ Series to R/3,by converting data(in any format) into IDocs).He is not ready to go for XI.
    The Problem area is a functionality which requires the non-SAP software to send XML file along with an attached Zip file.So,XML document,basically,has a 'zippedFile' XML element having actual file in XML keyword 'file'.
    This XML document ideally, should be converted by the subsystem(MQSeries link for R/3) into IDocs i.e. into a stream which could be stored in a table on R/3 side and later, sent back to the non-SAP software through MQ Series link to be converted into zip-file again with corresponding pdfs,images.I want someone who has worked in a similar scenario to confirm this.

    Hi,
    I have a feeling I have posted this question in the wrong forum or maybe I will let you decide this.Any help would be appreciated (even the right forum name).
    My scenario requires integration of a non-SAP software which talks in XML with SAP R/3(4.6C).The customer has decided to go with 'MQ Series link for R/3' (which integrates any non-SAP application running on IBM MQ Series to R/3,by converting data(in any format) into IDocs).He is not ready to go for XI.
    The Problem area is a functionality which requires the non-SAP software to send XML file along with an attached Zip file.So,XML document,basically,has a 'zippedFile' XML element having actual file in XML keyword 'file'.
    This XML document ideally, should be converted by the subsystem(MQSeries link for R/3) into IDocs i.e. into a stream which could be stored in a table on R/3 side and later, sent back to the non-SAP software through MQ Series link to be converted into zip-file again with corresponding pdfs,images.I wanted someone who has worked in a similar scenario to confirm this.

  • How to read large files(20-30 MB) using File/FTP adapters.

    Hi All,
    I am using JDev 10.1.3.3 and SOA 10.1.3.3.
    In my project some times i am getting files of size 20MB to 30MB.
    And the data of the file is in binary form.
    How can i read these type of files.
    I think batching is not possible because data is in binary form.
    Please help me out...
    Regards
    PavanKumar.

    Hi Anirudh,
    the tips provided in technotes are not suitable to my process structure.
    In my case data will be in binary format.
    First i need to read the payload and later in my process i have to archive that using a web service.

  • How to upload a file to different location using CS Template

    Hi,I have a Data Entry Template with a "File" field and when I upload a document it uploads in the same directory where the Content Item is created. Is there any way to upload the document to some other directory in the Content Server. Say I have a Html folder and there is a template which has a 'file' field. After Saving the content item the uploaded file gets saved in the same folder (Html) in content server, I would like to upload the document in a different folder called "Docs" and the content item in Html folder.Is it possible? If yes then can you please guide me.Thanks,Yaju

    Hi Rajesh,
    Use below code on your "Upload" Action:
         try
    // Give full path of folder on server where you want to upload the file.
              File file = new File("D:\\usr\\sap\\Images\\"+wdContext.currentContextElement().getResource().getResourceName().toString());
    // D:\usr\sap\Images folder should present on server
              FileOutputStream op = new FileOutputStream(file);
              if(wdContext.currentContextElement().getResource()!=null)
                   text=wdContext.currentContextElement().getResource().read(false);
                        while((temp=text.read())!=-1)
                             op.write(temp);
              op.flush();
              op.close();
         catch(Exception e)
              wdComponentAPI.getMessageManager().reportSuccess("Error while uploading file : "+e.getMessage());
    Thanks
    Sandy

  • How to read PDF files which are made using LiveCycle in VS

    Hello,
    I make some pdf templates using LiveCycle.
    I want to get the value correspond to the field name of PDF files.
    For example, I create the text field which is named "Employee ID".
    and then i wanna get the value using "Employee ID" in VS, especially, VB.NET 2005.
    Is this possible?
    Help me

    Haev a look at buying PDF4NET. This will do everything you require.

  • How to upload a file on SFTP location in java?

    Hi,
    I have csv file and I need to upload it on some SFTP location, can anybody please help me out?
    I have searched out but din't get such library for SFTP, please help me out.

    Is this a colleague of yours?
    Write a file to SFTP Server

  • How to read data from Linux named pipes using java?

    In linux box I want to get data from a named pipe(created using "mkfifo <filename>".
    How I can read the incoming data from the named pipe?

    there are some caveats though: if i remember correctly, when you reach the end of data in a fifo it will look like end-of-file and that may confuse some classes. So your mileage may vary

Maybe you are looking for

  • Error while opening Adobe Form Builder

    Hi all, I am trying to open an existing form in Adobe Form builder (TA SFP). When ever I display a standard form say FP_TEST_01 and go to the layout tab, I get an error saying <i><b>Error occurred in communication with layout editor</b></i>. I am usi

  • Why do printed contact lists wrap the data?

    I want to print out all of the people I have in the Contacts app to serve as a backup.  I was going to use the "Lists" style that is available, but noticed that there seems to be a bug.  In the print preview I noticed that it wraps email addresses an

  • So apparently I've been using a broken 3G for the last 3 years

    I waited in line and got my iPhone 3G the first day. Boy did that feel great, to hold some kind of alien tech in my hands. I always thought something was fishy with my phone though. I live on long island and I would assume the 3G service would be gre

  • CS4 and the patch tool

    After using the patch tool in CS4 I am unable to use the clone tool without closing photoshop and restarting it. Any ideas why this is happening?

  • Apex can't parse query on pipelined function

    Hi, I have a report based on a sql query which selects from a pipelined function. The pipeline function and the collection sql type it returns live in the parsing schema of the application. I get the error: "Query cannot be parsed within the Builder.