I am making a project which reads a text file contains thousands of tweets, reads the file, splits the hastags and make operations on them. I wrote a text file by myself and everything worked fine. I tried to use text file in this website http://www.cis.upenn.edu/~cdmurphy/cit595/homework/tweets.txt and I got a problem. Part of my code is :
while (scan.hasNext())
{
//Operations
}
When I use the text file on that website, code skips this loop. According to Java, that text file hasn't got next lines. Can anybody tell me what's wrong with that file? Since my project will be graded by using that text file, I have to find the problem.
Related
I am basically trying to write to a csv file, one of the cells in that csv file will contain multiple lines but one cell. I have read online that if you wrap it around "" you will generally be fine. This is the case in finder, however when I try to open it in excel it does not work that way what is your suggestion
Try to use this tutorial.
https://www.baeldung.com/apache-commons-csv
But, post your code to more detailed response
I've been googling and I've not found one example for this.
I am able to extract the contents for a DOCX file but so far no clue how to get the contents of an EXCEL file.
I know you use
SpreadsheetMLPackage spreadsheetMLPackage = SpreadsheetMLPackage.load(file);
to load the file, but I don't know how to proceed from here. I've check whatever methods SpreadsheetMLPackage has but nothing has gotten me the contents.
First you need to understand the structure of a xlsx file.
Unzip one, or run it through the docx4j webapp.
For how the parts relate to one another, see:
http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2007/08/13/1970.aspx
I guess the key method you'll want is getWorksheet
But first you'll need to get the WorkbookPart; do that with spreadsheetMLPackage.getWorkbookPart()
I would like to read a file from last line using RandomAccessFile. Is this possible or do I have to use another class?
Beside this file changes during the time so the last line doesn't remain last forever. During the reading another, java program write on it. My question is: the program will see in the same time another java program write on the file, the changes?
Edit
Well suppose I have a server that write its faults in a error log file during it's running.another program reads every line.which should be the best way?
Yes reading a file from the bottom up is possible using RandomAccessFile:
Reading the Last Line of a File in Java through Random Access
as for the other part of your question:
Beside this file changes during the time so the last line doesn't
remain last forever.During the reading another java program write on
it.My question is: the program will see in the same time another java
program write on the file, the changes?
I would propose a SSCCE in which you show what you are trying to accomplish and the problem
EDIT:
As Jon Skeets comment suggests, I found a link to a similar question answered by him: Quickly read the last line of a text file?
EDIT 2:
I think I got your second question, I'm not sure it's possible, as a single file cant be accessed by 2 different streams at the same time, one will just throw an error when trying to open the file. Ypu can however monitor if changes occur after the file has been read using Java.NIO Directory Watcher, Unless I misunderstood you.
I'm having trouble adding to an exsisting line in a text file without overwriting that particular line or adding a new line.
for example, i have a line in my text file which is:
hello my name is
I would like to add to this line so it becomes:
hello my name is joe bloggs
Thanks
i have a task to create a help desk program and i am trying to incorporate a feature that enables users to edit questions they have posted. as a result, the program will need to be able to append Any line within the text file - not necessarily just the last line
If it's not at the end of the file, you're in trouble - you're basically talking about inserting data in the middle of a file, which isn't traditionally supported by file systems.
The normal way to approach this is to create a new file - copy the portion before the insertion point from the old file, then write your new data, then copy the remainder of the original file afterwards. Finally, do whatever renaming/deleting you need.
I have to read some data from a .txt file. Each row contains a string.
Each string has to be displayed in a specific JTextField.
How can i solve the problem?
Thanks
Read the file line by line as described in the Java Tutorial | Reading, Writing, and Creating Files.
Call setText to set the text in a specific JTextField. e.g.
jTextField.setText(line);