Sample code to read a text file from UNIX directory.

I am using 9i Developer Suite, application server is 9.0.4. I want some help on how to read a flat file from UNIX environment. A sample code could be very helpful.
In windows, i use this kind of code:-
I declare an object & then write to a file using these sample staements:-
file_handle text_io.file_type;
filename := 'd:\ran\egs\uninvoiced.txt';
file_handle:=text_io.fopen(filename,'w');
text_io.put_line(file_handle, 'MOBILE NO '||'COUPON NO ' || 'DATE');
I hope, my question is clear. Please help in solving the doubt.
Regards.

filename := 'd:\ran\egs\uninvoiced.txt';This is a Windows directory, so it won't work on Unix.
For the rest of the code: see examples in the Forms Builder Online Help.

Similar Messages

  • Reading a text file from a URL

    I am having problems trying to read a text file from a URL.
    This is the code i have been using:
    package Java;
    import java.net.*;
    import java.io.*;
    public class Main_1 {
    public static void main(String[] args) throws Exception {
         URL myAddress = new URL("http://www.geocities.com/simonrobinson1/java/farrago.txt");
         BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        myAddress.openStream()));
         String inputLine;
         while ((inputLine = in.readLine()) != null)
         System.out.println(inputLine);
         in.close();
    but it returns an error saying:
    java.net.NoRouteToHostException: Operation timed out: no further information
    at java.net.PlainSocketImpl.socketConnect(Native Method) .....etc etc.
    Is this just a problem due to my network or is there something wrong with my code ????

    Altho you can access the file by typing the URL in a browser, geocities being a free web-hosting service don't like you to access the materials without seeing their ads. You have to find a way to trick it into thinking that you are indeed coming in from a web browser even tho you aren't.
    V.V.

  • Read a text file from DB directly (don't use PLSQL).

    how can I Read a text file from DB directly (don’t use PLSQL). ?

    If there is a known structure, you could use External Table access and query that "file" as any table.
    Nicolas.

  • How to read a text file from a Jar file

    Hi
    How can I read a text file from a Jar file?
    Thanx in advance..

    thanx
    helloWorld it works.damn, I didn't remove it fast enough. Even if it is urgent, it is best not to mention it, telling people just makes them take longer.

  • How can I read only text files in a directory.

    I've written a program to read files in a directory but I'd like for it to only read the text files of that directory.
    import java.io.*;
    public class Data {
      public static void main(String[] args) throws IOException {
      String target_dir = "C:\\files";
      File dir = new File(target_dir);
      File[] files = dir.listFiles();
      for (File textfiles : files) {
      if (textfiles.isFile()) {
      BufferedReader inputStream = null;
      try {
      inputStream = new BufferedReader(new FileReader(textfiles));
      String line;
      while ((line = inputStream.readLine()) != null) {
      System.out.println(line);
      } finally {
      if (inputStream != null) {
      inputStream.close();

    You have mentioned you want to read only text files.
    If you are referring to some specific set of extentions, you can filter based on that.
    ex: you want to read only .txt files, you can add an if condition as below :
              if(textfiles.getName().endsWith(".txt")) {
                  // Add your code here
    Cheers
    AJ

  • Unix command to create a copy of file from unix directory

    Hi guys,
    what is the Unix command to create a copy of file from unix directory?
    Thanks a lot!

    If you haven't noticed, this is a ABAP forum.
    You can go to the UNIX thread instead and post it there,
    SAP on UNIX
    You can expect answers there

  • Reading a text file from a remote host. Authentication required.

    Hi frnds,
    I have to read a text file "config.txt" from a remote host "HOSTNAME". File is shared in a folder - "FOLDER" .
    If the folder is shared with no password protection then it works. But if the folder is password protected the code is unable to read the file.
    I know the UserName and PassWord of the shared folder. How to code for this.
    I don't want to share the Folder to everyone without a password.
    Kindly Help.
    try {
    FileReader fr=new FileReader("\\\\HostName\\folder\\config.txt");
    BufferedReader br=new BufferedReader(fr);
    String s=null;
    while((s=br.readLine())!=null)
    /* One line is read */
    fr.close();
    catch(Exception e)
    throw new Exception("Exception in ConfigConstants."+e.toString());
    urs
    Mishra

    ok.. let me define it clearly...
    By using ftp as a protocol how can I read a text file
    in remote machine........ kindly do reply....Have a look at this article:
    http://www.javaworld.com/javaworld/jw-04-2003/jw-0404-ftp.html
    and what are the prerequisities that are needed for
    such a type of operation.....(At least) an FTP server should be running on the machine where the text file resides.
    Message was edited by:
    prometheuzz
    Oh, you should have your keyboard fixed: the full stop key seems to be stuck, you have a lot of trailing ..... after each sentence.

  • Reading only Image files from a directory

    i am wanting to be able to read a directory but only obtain the Image files (ie, gif, jpeg, tiff, png etc) and ignore all other type of files.
    i have made a custom ImageFIlter class which extends FileFilter which works for adding a photo singly, as only image files are shown in the JFileChooser. however i am wanting to add a folder of photos at once.
    here is the code so far:
    File dir;
                        JFileChooser fc = new JFileChooser();
                        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                        //Handle open button action.
                        int returnVal = fc.showOpenDialog(MainAppGUI.this);
                        if (returnVal == JFileChooser.APPROVE_OPTION) {
                             dir = fc.getSelectedFile();
                             if (dir.isDirectory()) {
                                  File[] files = dir.listFiles(new FileFilter());
                                  for (int i = 0; i < files.length; i++) {
                                       if (files.isFile()) {
                                            try {
                                                 Photo PhotoAdded = workingCollection.addManyPhotos(files[i], canvas.getChangedMaxDim());
                                                 //need to also add it to the relevant vectors, ie
                                                 //for mouse over operations, or photos added after
                                                 //save.
                                                 if(!workingCollection.isDuplicate()){
                                                      photosToCheck.add(photoAdded);
                                                      canvas.addToGrid(photoAdded);
                                                      photosAddedAfterLoad.add(photoAdded);
                                                      canvas.repaint();
                                                 else{
                                                      //do nothing as it is already in the vectors.
                                            } catch (Exception er) {
                                                 // Do nothing. Bad mp3, don't add.
                                       // recurse through directories
                                       else {
                             } else {
                                  try {
                                       throw new IOException(
                                                 "Error loading files from a directory: "
                                                           + dir.getAbsolutePath() + " is not a "
                                                           + "directory");
                                  } catch (IOException e1) {
                                       // TODO Auto-generated catch block
                                       e1.printStackTrace();
    any ideas?

    it shouldnt be new FileFilter() there, it should be new ImageFilter() but it gives a compilation error saying i cannot apply that parameter to the listFiles() method in the File class

  • Reading only Image Files from a Directory and ignoring the rest

    i am wanting to be able to read a directory but only obtain the Image files (ie, gif, jpeg, tiff, png etc) and ignore all other type of files.
    i have made a custom ImageFIlter class which extends FileFilter which works for adding a photo singly, as only image files are shown in the JFileChooser. however i am wanting to add a folder of photos at once.
    here is the code so far:
    File dir;
                        JFileChooser fc = new JFileChooser();
                        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                        //Handle open button action.
                        int returnVal = fc.showOpenDialog(MainAppGUI.this);
                        if (returnVal == JFileChooser.APPROVE_OPTION) {
                             dir = fc.getSelectedFile();
                             if (dir.isDirectory()) {
                                  File[] files = dir.listFiles(new ImageFilter());
                                  for (int i = 0; i < files.length; i++) {
                                       if (files.isFile()) {
                                            try {
                                                 Photo PhotoAdded = workingCollection.addManyPhotos(files[i], canvas.getChangedMaxDim());
                                                 //need to also add it to the relevant vectors, ie
                                                 //for mouse over operations, or photos added after
                                                 //save.
                                                 if(!workingCollection.isDuplicate()){
                                                      photosToCheck.add(photoAdded);
                                                      canvas.addToGrid(photoAdded);
                                                      photosAddedAfterLoad.add(photoAdded);
                                                      canvas.repaint();
                                                 else{
                                                      //do nothing as it is already in the vectors.
                                            } catch (Exception er) {
                                                 // Do nothing. Bad mp3, don't add.
                                       // recurse through directories
                                       else {
                             } else {
                                  try {
                                       throw new IOException(
                                                 "Error loading files from a directory: "
                                                           + dir.getAbsolutePath() + " is not a "
                                                           + "directory");
                                  } catch (IOException e1) {
                                       // TODO Auto-generated catch block
                                       e1.printStackTrace();
    any ideas?

    I'm confused.
    You already ARE using a FileFilter to only pick up image files. Whats the problem?
    If you need to recurse directories you need to change your code only a little.
    Write your method
    JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    //Handle open button action.
    int returnVal = fc.showOpenDialog(MainAppGUI.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      dir = fc.getSelectedFile();
    if (dir.isDirectory()) {
      scanDirectory(dir);
    else{
      // not a directory
    public void scanDirectoryForPhotos(File directory){
      // taking your code
    if (dir.isDirectory()) {
      File[] files = dir.listFiles(new ImageFilter());
      for (int i = 0; i < files.length; i++) {
        if (files.isFile()) {
    // details deleted
    // recurse through directories
    else {
    scanDirectory(files[i]);
    Your exception handling is a little strange. You throw an exception only to catch it immediately to print a stack trace? Not exactly the most common handling I've seen. You should probably just throw the exception and let the next level down handle it.
    Cheers,
    evnafets

  • Reading a text-file from within a Jar-file...

    I've made a program, that reads from a text-file. And it works great. But when I try to put the program into a jarfile, I get a fileNotFoundException... I have the textfile both inside and outside the jarfile... with the same result.
    Does anyone know what I might be doing wrong?
    Thanx in advance!
    Martin

    Depends on the path you enter for the text file. If you simply put "filename.txt" then you should try to have the file in the same directory as the class which accesses the file.
    Cheers,
    H�vard

  • How to read a text file from other machine???

    I have a text file located in local machine. I use th e code below to retrieve data from that particular text file.
    String realPath     = (String)getServletContext().getRealPath("");
    BufferedReader holsFile = new BufferedReader(new FileReader(realPath + "/webpages/holidays.txt"));My question is , how could I retrieve the records from the tsxt file if the file is located in another machine or webserver?
    Thanks for advanced.

    It's ok to be new.
    The answer is yes. (But I'll let you look in the javadoc to see which package it's in).
    Also it may be worth understanding that there is no such thing as a "function" in java, operations are termed "methods". To go further, you should realise that URL is a class not a "function" or method. The parentheses mean you're calling the constructor.
    HTH
    /k1

  • Read a xml file from local directory, transform it and put in new local dir

    Hi,
    I have a simple requirement. I have one XML file in d://source folder. I want to read it, transform it and want to put the transformed xml file in new location d://target.
    I am new to OSB. Please help me out to complete the above requirement.
    Thanks in advance.
    Cheers.

    Use a polling file transport proxy service to read the file(d://source folder)
    Do the necessary transformation XML or MFL(if the file is fixed length strings) in the proxy service stages.
    Use a file transport business service to write the file to a directory(d://target).To be called from the proxy service route node.
    http://docs.oracle.com/cd/E17904_01/doc.1111/e15866/transports.htm

  • Getting list of files from Unix directory inclding files frm sub-directries

    Hi All,
            I am trying to use Fm 'SUBST_GET_FILE_LIST'  and
    'RZL_READ_DIR_LOCAL' for getting a list of all files in a Unix directory including files from sub-directories.
    In the first case I am getting an Exception called 'Access Error'
    and when I use the 2nd FM, I am not getting any output.
    Is there a special way to use these FMs.
    Kindly help.
    Regds,
    Shweta

    [url http://java.sun.com/developer/JDCTechTips/2003/tt0122.html#1]READING FILES FROM JAVA ARCHIVES (JARS)

  • How to read a text file from Visual Composer

    Hi VC Experts,
    Please suggest me how can we read a textfile from  the local machine and pull the data from Visual Composer.
    Regards
    Kiran

    Hy kiran, is not possible to read data from flat file and put it in visual composer but you can :
    1) load this file in BI by ETL, for example on DSO object and then you can create a bex query to retrive the data
    2) if you want display the content of this file , you can use KM.
    Regards,
    Andrea

  • Reading text file from database server in OA Page

    Hi Guys,
    I am trying to embed an applet with in an OA Page. The applet is used to mainly for showing Gantt chart. I have to pass my connection details from OA Page to applet, I dont pass directly the connection details to the applet so i am placing all the server details, user name and password in a text file on the database server.
    So from the OA Page i have to read the contents of the file on the database server and pass them to the applet using the <PARAM> tag. My question is how to read the text file from the database server.Any Inputs?
    Thanks in advance for your help.
    Regards,
    Nagesh Manda.

    If the file to be read is on the database, then it makes sense to use the pl/sql code to read the file. Make a call to this pl/sql code from page controller to get back the values.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for