Read and write file on Windows XP.
I have a small program which simply reads a text file, gets the second line and changes it and writes a clone file with the second line changed. Basically it looks like that: main :: IO() main =do -- Some code here hexFile <- catch (readFile "int.hex") (\_ -> do putStrLn "File int.hex not found" getLine exitWith ExitSuccess) --some code here newLine <- outputLine keyno key (lines(hexFile)) --finish code for main function here outputLine keyno key orgFile = do -- Some code that modifies second line here newHexFile <- openFile "newint.hex" WriteMode hPutStrLn newHexFile (orgFile!!0 ++ "\n" ++ final ++ unlines (drop 2 orgFile)) The final variable above is the string containing the second line. What happens is everything works fine on my PC (Windows 2000) but on another PC (Using Windows XP) it sometimes gives a file which is incomplete, a couple of lines missing in the end making the file smaller and wrong. So I was wondering could it be the computer itself or is there any issue with Windows XP when it comes to reading and writing files. I tried using openFileEx but to my surprise it says it is deprecated (Which function to se instead then?). Best Regards NooK
On Sun, Apr 24, 2005 at 06:01:34PM +0200, Alexandre Weffort Thenorio wrote:
outputLine keyno key orgFile = do -- Some code that modifies second line here newHexFile <- openFile "newint.hex" WriteMode hPutStrLn newHexFile (orgFile!!0 ++ "\n" ++ final ++ unlines (drop 2 orgFile))
What happens is everything works fine on my PC (Windows 2000) but on another PC (Using Windows XP) it sometimes gives a file which is incomplete, a couple of lines missing in the end making the file smaller and wrong.
Maybe try hClose'ing the newHexFile at the end of outputLine...? Best regards Tomasz
I think it might have solved it m8 (Worked the few times I tested). Thanks though I don't really understand why. Best Regards Alex ----- Original Message ----- From: "Tomasz Zielonka" <tomasz.zielonka@gmail.com> To: "Alexandre Weffort Thenorio" <alethenorio@home.se> Cc: <haskell@haskell.org> Sent: Sunday, April 24, 2005 7:56 PM Subject: Re: [Haskell] Read and write file on Windows XP.
On Sun, Apr 24, 2005 at 06:01:34PM +0200, Alexandre Weffort Thenorio wrote:
outputLine keyno key orgFile = do -- Some code that modifies second line here newHexFile <- openFile "newint.hex" WriteMode hPutStrLn newHexFile (orgFile!!0 ++ "\n" ++ final ++ unlines (drop 2 orgFile))
What happens is everything works fine on my PC (Windows 2000) but on another PC (Using Windows XP) it sometimes gives a file which is incomplete, a couple of lines missing in the end making the file smaller and wrong.
Maybe try hClose'ing the newHexFile at the end of outputLine...?
Best regards Tomasz
participants (2)
-
Alexandre Weffort Thenorio -
Tomasz Zielonka