Java - unix file to windows file

I have a java program which saves a file to disk in linux which is then attached and emailed. The file is saved and opened in windows, so I want the file to be saved as a windows file.
I have tried replacing the LineFeeds(LF) with CRLF with the command dataBuf.replaceAll("\n","\r\n"), but this does not work. dataBuf is simply a string and is saved to file.
what can I do to the string in order to save it properly as a windows file?
Thanks

jverd wrote:
1. Read the docs for replaceAll(), carefully.
2. If you can't figure it out, then, as I already suggested, provide an [url http://sscce.org]SSCCE that demonstrates your problem, and explain clearly exactly what is going wrong. "It doesn't work" contains no information.
And, to make it easy, http://tinyurl.com/StringReplaceAll
¦ {Þ                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • How to access a file in Unix server from windows using java

    I want to access a file in unix server from windows using java program.
    I have the following code. I am able to open the url in a web browser.
    String urlStr="ftp:user:passwd@unix-server:ftp-port//javatest/test.csv;type=i";
    URL url = new URL(urlStr);
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream)));
    String inputLine;
    while((inputLine=in.readLine()))!=null){
    System.out.println(inputLine);
    in.close();
    I get the following error
    java.io.FileNotFoundException: /javatest/test.csv
    at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:333)
    at java.net.URL.openStream(URL.java:960)
    at com.test.samples.Test.main(Test.java:45)

    urlStr="ftp:user:passwd@unix-server:ftp-port//javatest/test.csv;type=i";
    I have given the format of the urlStr that I am using in the code. The actiual values are used in my code. I have tried pasting this url in the browser and it opens the file.

  • A utility like Unix 'file' in Java?

    Does any one know of a utility like the standard Unix utility 'file' that is written in Java?
    'file' does more than look at filename extensions. It maintains a list of rules for identifying many file types based on their contents.
    Thanks,
    bw

    Hi,
    This is in relation to your previous post about Marshalling.
    Were you ever able to work this problem out?
    I am currently trying to DeMarshal a XML input stream back to a SOAP object. But for some reason my Object Marshalling class does not seem to execute. I have been able to Marshal an object to a SOAP object but the reverse does not seem to work.
    Could you please shed some light on this problem?
    Thanks.
    XML and JAXB are new to me (well, I guess JAXB's new to everyone) so please excuse the elementary nature of this question.
    Is it possible to marshall an arbitrary Java object to XML without explicitly writing a DTD?
    I'm interested in storing instance of Java objects as XML, rather than serializing them. Is this possible? Is it crazy? Are there restriction on the kinds of objects that can be marshalled?
    Eg. could a class like
    public class ClassX {   Image img;   URL u;   long l;   String s;    public void someMethod() {}}
    be marshalled?
    Thanks,
    bw

  • File Transfer From Unix server to Windows Client System Using WebUtil

    Hi all,
    I want to Transfer a File from Unix Server to Window Client System using Webutil. But below mention code is not working.
    DECLARE
         V_Server_Path VARCHAR2(500) := Null;
         V_Client_Path VARCHAR2(500) := Null;
    BEGIN
         V_Server_Path := '/proj/oraapps/viper/dev/reports/cache/Saveauftr.txt';
         V_Client_Path := 'C:\Migration\EU_Applications\Lima\OAS_WorkArea\Client\Saveauftr.txt';
         IF WebUtil_File_Transfer.Is_AS_Readable(V_Server_Path) THEN
         IF WebUtil_File_Transfer.AS_To_Client(V_Client_Path,V_Server_Path) THEN
              Message('Downloading the File ..... .... ... .. .');
              Message('Downloading Was Successfull ...');
              Message('File Transfer from Server Was Successfull ...');
         END IF;
    END IF;
    END;
    Can anyone suggest me,Why the above code is not working and what to do for solve the Problem.
    Regards
    Gany

    Hello,
    You have more chances to get an answer in the Oracle Forms OTN Forum :
    Forms
    Regards

  • MARS - NFS on Unix Services for Windows and deleting files

    Hello !
    I've prepared NFS server on W2k3 server with Unix Services for Windows installed. It works OK, the only problem is moveing/deleting files and folders. It seems like a problem with permissions for anonymous user. Does anybody have similar experience ?

    If you receive the following error message "Error ./pnarchiver Thread 2051:PN-0102:SQL error: ORA-01005: null password given; logon denied" then there is a Problem with archiving to NFS server. The directories for the archiving are properly created on the server but those directories remain empty. The workaround is that an inter operability issue exists between MARS and CygWin NFS server running on Windows 2003 server. To work around such inter operability issues, replace the NFS server with Microsoft Windows Services for Unix.

  • Can New Java 7 File API Path Objs Be Used For Windows Virtual Folders

    Hello,
    I'm trying to duplicate a JFileChooser's drop-down list containing root directories of the file system. For Windows machines, its combobox lists the roots in a nice tree-like layout. For example:
    + Desktop
      + Computer
        + Local Disk (C:)
        + Data (D:)I cannot find an offical way to do this; I ended up using a class called "ShellFolder" to do it. Based on the "File" objects returned by the "ShellFolder" operation, I wanted to use the "toPath" method of the "java.io.File" object to convert the object to a "java.io.file.Path" object. Unfortunately, when I try to convert it, a java.nio.file.InvalidPathException" occurs.
    Therefore, is there a way to use the the new Path object (provided by Java7's new File NIO APIs) that can map to Windows special virtual folders (like "My Computer" which is mapped to a CLSID like "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")?
    Note: It looks like NetBeans suffered from the same problem. See their bug report here: [https://netbeans.org/bugzilla/show_bug.cgi?id=214011] .
    Here's some sample code to reproduce the problem:
    static public void main(final String[] asArguments)
         javax.swing.SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run()
                   java.io.File homeFile = FileSystemView.getFileSystemView().getHomeDirectory();
                   System.out.printf("File obj for home dir = %s\r\n", homeFile.getAbsolutePath());
                   java.nio.file.Path homePath = homeFile.toPath();
                   System.out.printf("Path obj for home dir = %s\r\n", homePath.toString());
                   // get the root directories
                   java.io.File[] rootDirs = (java.io.File[]) sun.awt.shell.ShellFolder.get("fileChooserComboBoxFolders");
                   for (int nIdx = 0; nIdx < rootDirs.length; nIdx++) {
                        java.io.File nextRoot = rootDirs[nIdx];
                        System.out.printf("File obj for next root dir = %s\r\n", nextRoot.getAbsolutePath());
                        // Is this a bug?
                        //          When we encounter a special Windows folder,
                        //          like "My Computer" which has a filename of "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
                        //          why do we receive a "java.nio.file.InvalidPathException"?  Should it not resolve the path
                        //          to the virtual Windows folder of "My Computer", just like the java.io.File objects do?
                        //          If not, is there an alternative way to get that information using the new Java 7 File APIs?
                        java.nio.file.Path nextRootPath = nextRoot.toPath();
                        System.out.printf("Path obj for next root dir = %s\r\n", nextRootPath.toString());
                   } // for
              } // run
    } // mainEdited by: RhinoGuy on Aug 10, 2012 11:11 AM

    Hmm don't know about special folders but the File object does have a listRoots() method. Perhaps that only returns mapped drives on Windows though, I remember using it to create my own Eclipse type filechooser which I find a lot more user-friendly than the standard JFileChooser.

  • Open API App (Windows based) fails to open FMB on Unix file system

    My Open API, Windows based app, can successfully open and 'get' properties of FMBs stored in the Windows file system. However, it fails to load the FMB when the FMB resides on a networked Unix server. The same FMBs on Unix can be opened by the Windows based FormBuilder (over the network). I can copy the FMB down to Windows and without re-compiling the FMB, my Open API app can 'load' the FMB and 'get' all the properties. What suggestions can you give for debugging / resolving this? I need to be able to 'Load' the FMBs (through the Open API), that reside in the Unix file system, from Windows.
    JJ

    Generally, this is why we will tell you that accessing net shares is not supported and in places where it might even be supported, we would still suggest that it is not recommended. Accessing via net shares (especially through Windows) is often problematic. There are various performance and connectivity issues that, unfortunately fool you into believing that the product you are using is flawed when the problem is really a connection issue with the share.
    In your case, because you are not exactly using an Oracle product (initially), Oracle can't offer much anyway, but I would recommend against using shares whenever possible. If you need to access a file, copy it locally first, perform whatever task on it, then return the updated file to its origin. This method protects you from things like net failure and instability as well as the performance issues associated with accessing files remotely.

  • Java API getting unix file ownership(name, group..etc)

    I am looking for any standard or 3rd-paty Java API that retrieves unix file ownership (name, group..etc)
    Thanks.

    I don't like your chances of finding a standard library to pull Unix group and user ownership. That would be violating the whole theory of Java being OS agnostic. I'm also unaware of any 3rd party library that does this.
    That said, you can definitely do this. One way I can think of is making a Runtime call:
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
    You could use this to do an ls -l on a file and parse the result.
    This would of course be violating standard practice in J2EE when any access direct to the file-system is regarded as being a pretty bad idea. It would also make remove the write-once run-anywhere aspect to your code, though that may not concern you too much.
    cheers,
    Trevor Nielsen
    londonmiddleware.org

  • FTP files from Unix box to Windows ( Shell script )--inplemention in Apps

    Hi,
    I have an requirement like need to send files generated at a particular path in the UNIX sever into Windows machine.
    This should be a scheduler( can we create any shell script
    ) for this...
    Note : files generated at Unix move into Windows box....
    Please check and help on this... and let me know if any clarification required on my requirement.
    Thanks,
    Pavan K

    This is relatively easy to do. You will need to write the shell script code and register it as a concurrent program of type "Host". Pl see the Application Developer Guide (for 11i and R12) at http://www.oracle.com/technology/documentation/applications.html for details on how to register a shell script "Host" custom program.
    ML Docs 266268.1, 147455.1, 1013907.6 and 156636.1 have some more info too.
    HTH
    Srini

  • Unix Files on Windows Server (read)

    Hi NG,
    we transfer form several locations files to our R/3 System (4.72) via secure copy (rcp with SSH). We do not know if the data comes from windows (cr lf) or unix (/0) or even hosts.
    Is there a way to read the file with abap and convert the files to windows.
    The files are ASCII or even EBCDIC (host).
    Are there function within R/3 to convert files from ascii (unix) to ascii (windows) and from ebcdic to ascii (windows).
    Regards
    Stefan

    950010 wrote:
    As I wrote in my question that due to compliance issue we have been asked to create the directory (that is currently on the same unix server on which our db is physically installed) in any other server (no matter unix or windows).And if that remote server is not available? Or if network connectivity to the remote server fails? Or if there is severe network congestion between the Oracle server and remote server? What then?
    How is the process on the local server suppose to deal with errors when it attempts to create a CSV file on the remote server? Or deal with network bottlenecks that results in severe performance degradation when trying to create a CSV file? Or if there lacks freespace for creating the CSV file?
    What about security? How is the local Oracle server to authenticate itself with the remote server? How is the remote server to protect that directory share against unauthorised access?
    How is this remote server going to provide access to authorised s/w to these CSV files?
    Who (local or remote processes) is going to manage this directory share and ensure old CSV files are deleted and that there is sufficient freespace for new CSV files?
    There are a LOT of questions that need to be asked... BEFORE deciding on HOW technically to do it. As the technical decision will be based on the functional requirements and how to best meet these.
    Technically - there is Samba, NFS, FTP, SFTP, SCP, RDIST and a number of other methods that can be used. But without asking the above questions and getting proper business answers, selecting a specific technical method is very much premature.
    You are asking the wrong questions, and in the wrong forum. You need to determine the business requirements first.

  • Descriptions of java dll files for windows

    I'm new to java programming and would greatly appreciate of someone could guide to documentation on java dll files for SDK windows..
    thanks

    If you are new, you don't want to know about the DLLs since there are not much you really need to know except you are writing JNI methods. Even you are writing JNI methods, you don't really need to care about the DLLs. Also I did not notice that there is any documentation about the DLLs/SOs. If you really want it, you may want to get this book: The JavaTM Native Interface by Sheng Liang
    If you want toe documentations about JDK:
    http://java.sun.com/j2se/1.3/docs/index.html
    or
    http://java.sun.com/j2se/1.4/docs/index.html

  • Java.io.File performance and file stat on windows

    hi,
    i've written an application that needs to find out about a section of a file tree as fast as possible. For each file from a given directory it needs to know things like the files length, lastModified and if its a directory etc..
    My problem is that this is a bottleneck - the application is a end-user GUI and so the 20 odd seconds it can take is annoying, even with a progress bar. I'm not sure why its taking so long - i've not done the tests yet but am pretty sure that a native routine would be much faster.
    I'm thinking that each call to File.length or File.isDirectory returns to the disk per method invokation to see whats happened. Although this is correct, it would be nicer to able to say something like get me a snapshot of the file (so it collects all the information at the same time) and have an explicit method for updating the snapshot. Does anyone know if this is correct?
    thanks,
    asjf
    http://onesearch.sun.com/search/developers/index.jsp?qt=%2B+%2Bjava.io.File+slow&col=javabugs&category=&state=&query=java.io.File+slow

    hi,
    ShellFolder also seems to work great :)
    It seems to have the same performance characteristics as the snapshot code on the network drive, but for local disk drives it seems maybe 10% faster again - why is this not part of the j2se libraries??? maybe JSR203 will provide something equivalent..
    thanks again,
    asjf
    import java.io.*;
    import java.lang.reflect.*;
    public final class FileTricks {
       private static Class cShellFolder, cShellFolderManager;
       private static Constructor ctrShellFolderManager;
       private static Method mCreateShellFolder;
       private static Object sfm;
       static {
          try {
             cShellFolder = Class.forName("sun.awt.shell.ShellFolder");
             cShellFolderManager = Class.forName("sun.awt.shell.ShellFolderManager");
             ctrShellFolderManager = cShellFolderManager.getDeclaredConstructor(new Class [] {});
             ctrShellFolderManager.setAccessible(true);
             sfm = ctrShellFolderManager.newInstance(new Object [] {});
             mCreateShellFolder = cShellFolderManager.getDeclaredMethod("createShellFolder",new Class [] {File.class});
             mCreateShellFolder.setAccessible(true);
          } catch(Exception e) {
             e.printStackTrace();
             cShellFolder = cShellFolderManager = null;
             ctrShellFolderManager = null;
             mCreateShellFolder = null;
             sfm = null;
       public static final File attemptReplaceWithShellFolder(File actual) {
          File result = actual;
          if(cShellFolder != null && !cShellFolder.isInstance(actual)) {
             try {
                result = (File) mCreateShellFolder.invoke(sfm, (new Object [] {actual}));
                System.out.print(".");
             } catch(Exception e) {
                System.out.print("#");
          return result;
       public final static class FileSnapshot {
          private static Method mGetBooleanAttributes;
          private static int BA_DIRECTORY, BA_EXISTS, BA_REGULAR, BA_HIDDEN;
          private static Object fs;
          public final boolean isDirectory, exists, isRegular, isHidden;
          public FileSnapshot(File f) {
             boolean e, d, r, h;
             try {
                int ba = ((Integer)mGetBooleanAttributes.invoke(fs, new Object [] {f})).intValue();
                d = (ba & BA_DIRECTORY)!=0;
                e = (ba & BA_EXISTS)!=0;
                r = (ba & BA_REGULAR)!=0;
                h = (ba & BA_HIDDEN)!=0;
             } catch(Exception x) {
                d = f.isDirectory();
                e = d || f.exists();
                r = f.isFile();
                h = f.isHidden();
             isDirectory = d; exists = e; isRegular = r; isHidden = h;
          static {
             try {
                Class cFile = Class.forName("java.io.File");
                Class cFileSystem = Class.forName("java.io.FileSystem");
                mGetBooleanAttributes = cFileSystem.getDeclaredMethod("getBooleanAttributes", new Class [] {File.class});
                Field fBA_EXISTS = cFileSystem.getDeclaredField("BA_EXISTS");
                Field fBA_REGULAR = cFileSystem.getDeclaredField("BA_REGULAR");
                Field fBA_DIRECTORY = cFileSystem.getDeclaredField("BA_DIRECTORY");
                Field fBA_HIDDEN = cFileSystem.getDeclaredField("BA_HIDDEN");
                Field fFs = cFile.getDeclaredField("fs");
                mGetBooleanAttributes.setAccessible(true);
                fFs.setAccessible(true);
                fBA_EXISTS.setAccessible(true);
                fBA_REGULAR.setAccessible(true);
                fBA_DIRECTORY.setAccessible(true);
                fBA_HIDDEN.setAccessible(true);
                BA_EXISTS = ((Integer)fBA_EXISTS.get(null)).intValue();
                BA_REGULAR = ((Integer)fBA_REGULAR.get(null)).intValue();
                BA_DIRECTORY = ((Integer)fBA_DIRECTORY.get(null)).intValue();
                BA_HIDDEN = ((Integer)fBA_HIDDEN.get(null)).intValue();
                fs = fFs.get(null);
             } catch(Exception e) {}
    }

  • Java script in HTMLDB to check if file exists in Unix file system

    How do I use javascript to check if file is exists in Unix file system. I would like to dispaly the columns only if file is exists.

    Hello,
    This is one of those features that the manuals do not cover.
    How to use and build AJAX features could be a whole book all by itself, and it's not really HTML DB specific feature even though we have built some hooks in application and javascript to make it easier.
    Take a look at this thread
    Netflix: Nice UI ideas
    and I've built some examples here
    http://htmldb.oracle.com/pls/otn/f?p=11933:11
    Or just search the forums for AJAX or XMLHTTP
    Carl

  • Java.io.File and uppercase/lowercase

    Hello,
    I am running into a weird problem with java.io.File on a Windows system. My program needs to validate a path the user entered. Sometimes, the path will contain a directory name that should be uppercase, but which the user entered in lowercase instead, and the <File>.exists() returns true anyways. I know on Windows, on the command line, directory and file names are not case-sensitive, which is probably why it was done that way. But this is causing problems because once the path is (supposedly) validated, it is handed to a Unix program (case-sensitive), and if it's not really valid there, the user has no way of correcting it. Whereas if it were found as invalid in the Java program, I could pop up an error, and the user could correct it.
    The bottom line is, is there a way of telling a File object to return false if the path name is not EXACTLY identical, on Windows? Or would I have to check the path myself, without relying on File?
    Thanks in advance,
    J-S

    In this case, this is not acceptable, since the files or directories on disk can be in any case. I just need the entered case to be exactly the same as the files.
    In other terms, I need File.exists() to return false if the case does not match. I would think there is a way to do this, since internally, the function checks if the operating system is Windows or Unix before doing the comparison, and acts differently in each case...
    From http://java.sun.com/j2se/1.3/docs/api/java/io/File.html (see equals or compareTo method) :
    "On UNIX systems, alphabetic case is significant in comparing pathnames; on Win32 systems it is not."
    I would like to force the Unix way of doing.

  • Nfs mount point does not allow file creations via java.io.File

    Folks,
    I have mounted an nfs drive to iFS on a Solaris server:
    mount -F nfs nfs://server:port/ifsfolder /unixfolder
    I can mkdir and touch files no problem. They appear in iFS as I'd expect. However if I write to the nfs mount via a JVM using java.io.File encounter the following problems:
    Only directories are created ? unless I include the user that started the JVM in the oinstall unix group with the oracle user because it's the oracle user that writes to iFS not the user that creating the files!
    I'm trying to create several files in a single directory via java.io.File BUT only the first file is created. I've tried putting waits in the code to see if it a timing issue but this doesn't appear to be. Writing via java.io.File to either a native directory of a native nfs mountpoint works OK. ie. Junit test against native file system works but not against an iFS mount point. Curiously the same unit tests running on PC with a windows driving mapping to iFS work OK !! so why not via a unix NFS mapping ?
    many thanks in advance.
    C

    Hi Diep,
    have done as requested via Oracle TAR #3308936.995. As it happens the problem is resolved. The resolution has been not to create the file via java.io.File.createNewFile(); before adding content via an outputStream. if the File creation is left until the content is added as shown below the problem is resolved.
    Another quick question is link creation via 'ln -fs' and 'ln -f' supported against and nfs mount point to iFS ? (at Operating System level, rather than adding a folder path relationship via the Java API).
    many thanks in advance.
    public void createFile(String p_absolutePath, InputStream p_inputStream) throws Exception
    File file = null;
    file = new File(p_absolutePath);
    // Oracle TAR Number: 3308936.995
    // Uncomment line below to cause failure java.io.IOException: Operation not supported on transport endpoint
    // at java.io.UnixFileSystem.createFileExclusively(Native Method)
    // at java.io.File.createNewFile(File.java:828)
    // at com.unisys.ors.filesystemdata.OracleTARTest.createFile(OracleTARTest.java:43)
    // at com.unisys.ors.filesystemdata.OracleTARTest.main(OracleTARTest.java:79)
    //file.createNewFile();
    FileOutputStream fos = new FileOutputStream(file);
    byte[] buffer = new byte[1024];
    int noOfBytesRead = 0;
    while ((noOfBytesRead = p_inputStream.read(buffer, 0, buffer.length)) != -1)
    fos.write(buffer, 0, noOfBytesRead);
    p_inputStream.close();
    fos.flush();
    fos.close();
    }

Maybe you are looking for