Results 1 to 4 of 4

Thread: [Java] read and write a file

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: [Java] read and write a file

    IMO: here a symply BufferedReader to read & write file or buffer ... on QThread

    I use it to send Image frame movie over QEvent at just time

    http://fop-miniscribus.googlecode.co...t/image_event/


    Qt Code:
    1. /* device to write or read from QThread or not */
    2.  
    3. class StreamFile
    4. {
    5. public:
    6. StreamFile()
    7. :d(new QBuffer())
    8. {
    9. d->open(QIODevice::ReadWrite);
    10. start();
    11. }
    12. ~StreamFile()
    13. {
    14. d->close();
    15. }
    16. bool clear()
    17. {
    18. d->write(QByteArray());
    19. return d->bytesAvailable() == 0 ? true : false;
    20. }
    21. void start() {
    22. d->seek(0);
    23. }
    24. bool LoadFile( const QString file ) {
    25. if (clear()) {
    26. QFile f(file);
    27. if (f.exists()) {
    28. if (f.open(QFile::ReadOnly)) {
    29. d->write(f.readAll());
    30. f.close();
    31. start();
    32. return true;
    33. }
    34. }
    35. }
    36. return false;
    37. }
    38. bool PutOnFile( const QString file ) {
    39. QFile f(file);
    40. if (f.open(QFile::WriteOnly)) {
    41. uint bi = f.write(d->readAll());
    42. start();
    43. return bi > 0 ? true : false;
    44. }
    45. return false;
    46. }
    47. QBuffer *device() { return d; }
    48. bool isValid() { return img.loadFromData(stream()); }
    49. QByteArray stream() { return d->data(); }
    50. QImage img;
    51. QBuffer *d;
    52. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default Re: [Java] read and write a file

    sorry, but I need to use Java with standard library (not QT)....My question was focused on '\n' problem....

    thanks.
    Regards

Similar Threads

  1. How can I Read Write Excel File
    By xingshaoyong in forum Qt Programming
    Replies: 6
    Last Post: 13th July 2011, 20:16
  2. structures to a file (read and write)
    By baray98 in forum Qt Programming
    Replies: 5
    Last Post: 10th February 2008, 20:12
  3. How to open a file in Read Write mode
    By merry in forum Qt Programming
    Replies: 13
    Last Post: 16th November 2007, 14:40
  4. Read \Write Excel File using Qt
    By xingshaoyong in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 22:07
  5. FSWriteFork in MAC OS to write data to a file.
    By vishal.chauhan in forum General Programming
    Replies: 5
    Last Post: 2nd July 2007, 06:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.