file-writing

Writing a “\\n” in a text file

爱⌒轻易说出口 提交于 2019-12-05 09:03:23
I'm trying to write a string \n in a text file. But the result in the text file is a newline. I know that the \n represents a newline. But in my case, I really need to see the String \n, not the newline. How can I solve this? Charles Keepax The \ character escapes the next character, as you say \n will create a newline. If you wish to output an actual \, you need to write: "\\n" That way the first slash escapes the second slash, generating an actual slash rather than escaping the n. Use "\\n" . The first backslash escapes the second one and as a result one is printed to your output. you have

Modifying JSON file using Golang

試著忘記壹切 提交于 2019-12-04 21:10:57
I am attempting to read in a JSON file in Golang, modifying this JSON file, and then creating a new JSON file/writing over this JSON file. I have seen several samples online, but can't seem to put two and two together to get the required result. I tried just making my own JSON str in GO and modifying that, but have still failed. package main import ( "encoding/json" "fmt" ) type Person struct { Name string Age int Details interface{} } func main() { //I created a simple Json structure here to play with str := `{"name": "A", "age":20, "details": {"salary":100000000} }` var data Person err :=

How to remove \\n and \\r from a string

泪湿孤枕 提交于 2019-12-04 02:13:26
I currently am trying to get the code from this website: http://netherkingdom.netai.net/pycake.html Then I have a python script parse out all code in html div tags, and finally write the text from between the div tags to a file. The problem is it adds a bunch of \r and \n to the file. How can I either avoid this or remove the \r and \n. Here is my code: import urllib.request from html.parser import HTMLParser import re page = urllib.request.urlopen('http://netherkingdom.netai.net/pycake.html') t = page.read() class MyHTMLParser(HTMLParser): def handle_data(self, data): print(data) f = open('

How do you instantly update an XML document after you add a node to it?

这一生的挚爱 提交于 2019-12-02 22:51:13
问题 So I'm making a calendar program and I need it to update when you add a new entry to it. Right now, I need to click on the xml file to get it to update, then everything else works fine. Declaration: private DocumentBuilderFactory documentFactory; private DocumentBuilder documentBuilder; private Document xmlDoc; private Node rootNode; private static Node dataNode; Assignment in constructor: try { documentFactory = DocumentBuilderFactory.newInstance(); documentBuilder = documentFactory

How do you update an XML file after you change a node? [duplicate]

蹲街弑〆低调 提交于 2019-12-02 13:20:00
问题 This question already has an answer here : How do you instantly update an XML document after you add a node to it? (1 answer) Closed 4 years ago . I'm using Node.setTextContent() to edit a node but it's not changing anything in the file. If I print the text content after it will appear as changed but it will not persist after the program is closed. for (int y=0; y<calendarDataNode.getChildNodes().getLength(); y++) { //if (year node name == "y" + current year) if (calendarDataNode

How do you instantly update an XML document after you add a node to it?

不打扰是莪最后的温柔 提交于 2019-12-02 12:57:59
So I'm making a calendar program and I need it to update when you add a new entry to it. Right now, I need to click on the xml file to get it to update, then everything else works fine. Declaration: private DocumentBuilderFactory documentFactory; private DocumentBuilder documentBuilder; private Document xmlDoc; private Node rootNode; private static Node dataNode; Assignment in constructor: try { documentFactory = DocumentBuilderFactory.newInstance(); documentBuilder = documentFactory.newDocumentBuilder(); xmlDoc = documentBuilder.parse(Main.class.getResourceAsStream("Calendar.xml")); rootNode

Proper way of waiting until a file is created

天涯浪子 提交于 2019-12-02 05:47:19
问题 I have the following code: // get location where application data director is located var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); // create dir if it doesnt exist var folder = System.IO.Path.Combine(appData, "SomeDir"); if (System.IO.Directory.Exists(folder) == false) System.IO.Directory.CreateDirectory(folder); // create file if it doesnt exist var file = System.IO.Path.Combine(folder, "test.txt"); if(System.IO.File.Exists(file)== false) System.IO.File

Error in Writing to Image file from PHP

南楼画角 提交于 2019-12-02 05:09:48
问题 I am attempting to write to an image file from a blob. if($_POST['logoFilename'] != 'undefined'){ $logoFile = fopen($_POST['logoFilename'], 'w') or die ("Cannot create ".$_POST['logoFilename']); fwrite($logoFile, $_POST['logoImage']); fclose($logoFile); } In the previous code snippet, $_POST['logoImage'] is a BLOB. The file is correctly written to the root directory, however the file cannot be opened. In ubuntu 11.04 I receive the following error: Error interpreting JPEG image file (Not a

How do you update an XML file after you change a node? [duplicate]

霸气de小男生 提交于 2019-12-02 04:01:19
This question is an exact duplicate of: How do you instantly update an XML document after you add a node to it? 1 answer I'm using Node.setTextContent() to edit a node but it's not changing anything in the file. If I print the text content after it will appear as changed but it will not persist after the program is closed. for (int y=0; y<calendarDataNode.getChildNodes().getLength(); y++) { //if (year node name == "y" + current year) if (calendarDataNode.getChildNodes().item(y).getNodeName().equals("y" + Main.year)) { //for (int m=0; m<number of child nodes of year node; m++) for (int m=0; m

Error in Writing to Image file from PHP

耗尽温柔 提交于 2019-12-02 02:12:15
I am attempting to write to an image file from a blob. if($_POST['logoFilename'] != 'undefined'){ $logoFile = fopen($_POST['logoFilename'], 'w') or die ("Cannot create ".$_POST['logoFilename']); fwrite($logoFile, $_POST['logoImage']); fclose($logoFile); } In the previous code snippet, $_POST['logoImage'] is a BLOB. The file is correctly written to the root directory, however the file cannot be opened. In ubuntu 11.04 I receive the following error: Error interpreting JPEG image file (Not a JPEG file: starts with 0x64 0x61). The BLOB does correctly display if I create an img and set its src=blob