Results 1 to 12 of 12

Thread: Java and Writer

  1. #1
    wing is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Smile Java and Writer

    I have open office installed my question is in the school have a permit for non-attendance is so

    Justification of absence

    Greenbow, .. August 2011


    I ............... identified with the card No. ............................. Specific did not attend the following problems without further ......................................., to say to reiterate my respect for the institution, I say goodbye.


    ...............................................
    student's name

    I want to replace the points put my name and put the number on my card all you need to replace hope you can help me I am new to this but I learn fast java thanks in advance

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    what is your question about i am not sure if you know what to ask but someone can help if you would ask a question about java programming this forum is to help java programmers so if this is a programming question please be specific

  3. #3
    wing is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default

    I want to write in my odt in a specific area, i have 14 plz do not be rude to me, i select my name from java and put inside to my odt but there other text just do not want to change

    I've been searching and found this

    Java Code:
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.Writer;
    
    public class ReadWriteTextFile {
    
      static public String getContents(File aFile) {
      
        StringBuilder contents = new StringBuilder();
        
        try {
       
          BufferedReader input =  new BufferedReader(new FileReader(aFile));
          try {
            String line = null; 
            while (( line = input.readLine()) != null){
              contents.append(line);
              contents.append(System.getProperty("line.separator"));
            }
          }
          finally {
            input.close();
          }
        }
        catch (IOException ex){
          ex.printStackTrace();
        }
        
        return contents.toString();
      }
      static public void setContents(File aFile, String aContents)
                                     throws FileNotFoundException, IOException {
        if (aFile == null) {
          throw new IllegalArgumentException("File should not be null.");
        }
        if (!aFile.exists()) {
          throw new FileNotFoundException ("File does not exist: " + aFile);
        }
        if (!aFile.isFile()) {
          throw new IllegalArgumentException("Should not be a directory: " + aFile);
        }
        if (!aFile.canWrite()) {
          throw new IllegalArgumentException("File cannot be written: " + aFile);
        }
        Writer output = new BufferedWriter(new FileWriter(aFile));
        try {
          output.write( aContents );
        }
        finally {
          output.close();
        }
      }
    
      /** Simple test harness.   */
      public static void main (String... aArguments) throws IOException {
        File testFile = new File("reaper.odt");
        System.out.println("ORIGINAL TEXT: " + getContents(testFile));
        setContents(testFile, "the data is overwrite...");
        System.out.println("TEXT: " + getContents(testFile));
      }
    }
    This overrides the words inside, but do not know how to say no to overwrite an important part of my document

    I hope to be clear I just want to put my name in java and is writing in the name just that thanks T_T

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    I want to write in my odt in a specific area
    What is an "odt"?

  5. #5
    wing is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default

    is like .doc but from open office I do not really matter if it is recorded as a word or a writer because it opens open office can you help me?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    If you want to write a java program to read a .odt file, change its contents and write it back out, you need to know the format of the .odt file. To test how hard it will be to write a program to do this, open the file in Notepad, make the changes to it that you want to make and save it. If the Open Office program can now read the file and display the original contents with your changes then it you can probably write a java program to do what you did with Notepad.

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Let me get this straight. You have an Open Office document. You have Open Office which can modify an Open Office document. But instead of doing that you want to go the hard route of writing a Java program to modify the document. WHY? You already have a program that can do that. Is Open Office Word compatible? Then you might be able to use Apache POI to achieve your goals.

  8. #8
    wing is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default

    java create any kind of file that's really funny. I write a text, doc but but I can not send a bold-type format in my title

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    That is because Java is not a word processor. You are trying to use the wrong tool for the job.

  10. #10
    wing is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default

    yes, but what happens is that I think in the future to write the whole school with a single button reading all the names of students and inserting them in the texts but I think only good is an illusion anyway thanks

  11. #11
    wing is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default


  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    Have you considered trying to do this using macros?
    It looks like a macro sort of thing, and OO has a reasonably powerful macro language I believe.

Similar Threads

  1. Encoding in java.io.writer
    By hariharabalan in forum New To Java
    Replies: 1
    Last Post: 12-06-2010, 10:27 AM
  2. Researcher's Writer - My Personal Project
    By GraceC1990 in forum Advanced Java
    Replies: 2
    Last Post: 10-23-2010, 06:06 PM
  3. creating word writer
    By Anchal in forum AWT / Swing
    Replies: 3
    Last Post: 04-06-2010, 09:00 AM
  4. CSV file writer
    By nida in forum Java Servlet
    Replies: 3
    Last Post: 05-08-2009, 02:08 PM
  5. [SOLVED] reader and writer on same file handle
    By Nicholas Jordan in forum Advanced Java
    Replies: 11
    Last Post: 07-01-2008, 03:39 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •