text-files

Java - delete line from text file by overwriting while reading it

倾然丶 夕夏残阳落幕 提交于 2019-11-26 21:03:10
I'm trying to delete a line of text from a text file without copying to a temporary file. I am trying to do this by using a Printwriter and a Scanner and having them traverse the file at the same time, the writer writing what the Scanner reads and overwriting each line with the same thing, until it gets to the line that I wish to delete. Then, I advance the Scanner but not the writer, and continue as before. Here is the code: But first, the parameters: My file names are numbers, so this would read 1.txt or 2.txt, etc, and so f specifies the file name. I convert it to a String in the

Read lines from a text file but skip the first two lines

不羁岁月 提交于 2019-11-26 20:57:52
问题 I've got this macro code in Microsoft Office Word 2003 which reads the lines of a text file. The lines each represent a string value that I need to use later in the code. However, the first two lines of the text file contains some stuff that I don't need. How can I modify the code so that it skips the two first lines? The "Intellisense" within the VBA editor in Word sucks hard btw.. Anyway, the code looks something like this Dim sFileName As String Dim iFileNum As Integer Dim sBuf As String

send a file to client

我的梦境 提交于 2019-11-26 20:26:19
问题 I want to write a text file in the server through Php, and have the client to download that file. How would i do that? Essentially the client should be able to download the file from the server. 回答1: In addition to the data already posted, there is a header you might want to try. Its only a suggestion to how its meant to be handled, and the user agent can chose to ignore it, and simply display the file in the window if it knows how: <?php header('Content-Type: text/plain'); # its a text file

Java - How Can I Write My ArrayList to a file, and Read (load) that file to the original ArrayList?

房东的猫 提交于 2019-11-26 20:09:23
I am writing a program in Java which displays a range of afterschool clubs (E.G. Football, Hockey - entered by user). The clubs are added into the following ArrayList : private ArrayList<Club> clubs = new ArrayList<Club>(); By the followng Method: public void addClub(String clubName) { Club club = findClub(clubName); if (club == null) clubs.add(new Club(clubName)); } 'Club' is a class with a constructor - name: public class Club { private String name; public Club(String name) { this.name = name; } //There are more methods in my program but don't affect my query.. } My program is working - it

J2ME/Blackberry - how to read/write text file?

痴心易碎 提交于 2019-11-26 19:54:54
问题 please give me a sample code for read/write text file in blackberry application. 回答1: My code snippet for string read/write files: private String readTextFile(String fName) { String result = null; FileConnection fconn = null; DataInputStream is = null; try { fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE); is = fconn.openDataInputStream(); byte[] data = IOUtilities.streamToBytes(is); result = new String(data); } catch (IOException e) { System.out.println(e.getMessage());

Best way to retrieve variable values from a text file?

故事扮演 提交于 2019-11-26 18:56:09
问题 Referring on this question, I have a similar -but not the same- problem.. On my way, I'll have some text file, structured like: var_a: 'home' var_b: 'car' var_c: 15.5 And I need that python read the file and then create a variable named var_a with value 'home', and so on. Example: #python stuff over here getVarFromFile(filename) #this is the function that im looking for print var_b #output: car, as string print var_c #output 15.5, as number. Is this possible, I mean, even keep the var type?

java replace specific string in textfile

夙愿已清 提交于 2019-11-26 18:35:53
问题 I've got a text file called log.txt It's got the following data 1,,Mon May 05 00:05:45 WST 2014,textFiles/a.txt,images/download.jpg 2,,Mon May 05 00:05:45 WST 2014,textFiles/a.txt,images/download.jpg the numbers before the first comma are indexes that specify each item. what I want to do is read the file then replace one part of the string(e.g. textFiles/a.txt) in a given line with another value(e.g. something/bob.txt). this is what i have so far File log= new File("log.txt"); String search =

How do I sort records in a text file using Java?

蓝咒 提交于 2019-11-26 18:29:43
问题 Some amendment of the data in txt file. I have tried the suggested code but Im not successfully write it again in the txt file with this format.I've tried the collection.sort but it write the data in long line. My txt file contain these data: Monday Jessica Run 20mins Alba Walk 20mins Amy Jogging 40mins Bobby Run 10mins Tuesday Mess Run 20mins Alba Walk 20mins Christy Jogging 40mins Bobby Run 10mins How can I sort those data in ascending order and store it again in txt file after sorting?

Modifying or deleting a line from a text file the low-level way?

家住魔仙堡 提交于 2019-11-26 17:51:34
问题 I'm working with a Text File in Delphi, and I don't wish to use the method of loading/saving with a string list. I intend to maintain an open filestream where I read and write my data there, keeping massive amounts of data on the hard disk instead of in the memory. I have the simple concept of writing new lines to a text file and reading them, but when it comes to modifying and deleting them, I cannot find any good resources. Each line in this file contains a name, and equals sign, and the

Convert 12-hour date/time to 24-hour date/time

末鹿安然 提交于 2019-11-26 17:51:32
I have a tab delimited file where each record has a timestamp field in 12-hour format: mm/dd/yyyy hh:mm:ss [AM|PM]. I need to quickly convert these fields to 24-hour time: mm/dd/yyyy HH:mm:ss. What would be the best way to do this? I'm running on a Windows platform, but I have access to sed, awk, perl, python, and tcl in addition to the usual Windows tools. Jonathan Leffler Using Perl and hand-crafted regexes instead of facilities like strptime: #!/bin/perl -w while (<>) { # for date times that don't use leading zeroes, use this regex instead: # (?:\d{1,2}/\d{1,2}/\d{4} )(\d{1,2})(?::\d\d:\d\d